Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 18 Apr 2015 09:53 PM |
I am making a set of elevator doors, and both doors open, then close after 4 seconds.
----
for i = 0, -0.3, -0.01 do script.Parent.Position = script.Parent.Position + Vector3.new (i, 0, 0) wait (0.1) end
wait(4)
for i = 0, 0.3, 0.01 do script.Parent.Position = script.Parent.Position + Vector3.new (i, 0, 0) wait (0.1) end
-----
I've put the script in each of the two elevator doors (because I am unsure of how to use one script for both doors?). How do I go about making a click function that would activate both doors? |
|
|
| Report Abuse |
|
|
|
| 18 Apr 2015 09:54 PM |
function onClick() --code end
script.Parent.ClickDetector:connect(onClick) script.Parent.Parent.GetToTheOtherDoor:connect(onClick) |
|
|
| Report Abuse |
|
|
|
| 18 Apr 2015 10:04 PM |
You can have multiple functions in a script.
function thing()
end
function otherThing()
end
And they can be connected independently.
thing() --Call the thing1 function whenever the server starts up, assuming script is enabled
Workspace.Part.Touched:connect(thing) -- Call thing when Part is touched
game.Players.PlayerAdded:connect(thing) -- When a player joins
All can be done in the same script. |
|
|
| Report Abuse |
|
|
Tokimonu
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 643 |
|
|
| 18 Apr 2015 10:05 PM |
also, to add onto @GreatOculus' post, you can make multiple functions run at the same time using coroutines
http://wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines
bark |
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 18 Apr 2015 10:27 PM |
@Summer
What is the reason behind what I've put in ***
script.*Parent.Parent*.GetToTheOtherDoor:connect(onClick)
Why are there two Parents? |
|
|
| Report Abuse |
|
|
|
| 18 Apr 2015 10:30 PM |
| He's just using an example. My assumption would be that he imagined the script being inside a part which inside of a model. |
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 18 Apr 2015 10:32 PM |
| Ah okay, makes sense, thank you. :) |
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 18 Apr 2015 10:36 PM |
So I've got two parts in a group, and this is the script in the part, the click detector is grouped aswell (outside of parts). Doesn't work
function onClick() for i = 0, 0.3, 0.01 do script.Parent.Position = script.Parent.Position + Vector3.new (i, 0, 0) wait (0.1) end
wait(4)
for i = 0, -0.3, -0.01 do script.Parent.Position = script.Parent.Position + Vector3.new (i, 0, 0) wait (0.1) end script.Parent.ClickDetector:connect(onClick) script.Parent.Parent.Door2:connect(onClick) end |
|
|
| Report Abuse |
|
|
|
| 18 Apr 2015 10:39 PM |
| ClickDetector (to my knowledge) has to be a child of a physical object in the workspace, i.e. a part. Move it inside one of the parts. |
|
|
| Report Abuse |
|
|
|
| 18 Apr 2015 10:41 PM |
script.Parent.ClickDetector.MouseClick:connect(onClick) script.Parent.Parent.Door2.ClickDetector.MouseClick:connect(onClick) |
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 18 Apr 2015 10:42 PM |
Done, not working, no errors in output...
Is this because I dont have the two scripts in one script? (theres one script for each door) |
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 18 Apr 2015 11:03 PM |
Ok.. so I whipped this up in hopes that putting both scripts into one would fix it, but it didn't work
function onClick() wait(2) for i = 0, 0.3, 0.01 do script.Parent.Door1.Position = script.Parent.Door1.Position + Vector3.new(i, 0, 0) end for i = 0, -0.3, -0.01 do script.Parent.Door2.Position = script.Parent.Door2.Position + Vector3.new(i, 0, 0) end wait(5) for i = 0, -0.3, -0.01 do script.Parent.Door1.Position = script.Parent.Door1.Position + Vector3.new(i, 0, 0) end for i = 0, 0.3, 0.01 do script.Parent.Door2.Position = script.Parent.Door2.Position + Vector3.new(i, 0, 0) end script.Parent.Door1.ClickDetector.MouseClick:connect(onClick) script.Parent.Door2.ClickDetector.MouseClick:connect(onClick) end |
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
| |
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
| |
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
|
| 19 Apr 2015 04:23 PM |
I removed click event temporarily to fix the script. Currently the doors open, and close, but theyre not following my for loops conditions (moving slowly by 0.01 studs to 0.3 studs).
They just immediately open, then immediately close.
Suggestions?
wait(2) for i = 0, 0.3, 0.01 do script.Parent.Parent.Door1.Position = script.Parent.Parent.Door1.Position + Vector3.new(i, 0, 0) end for i = 0, -0.3, -0.01 do script.Parent.Parent.Door2.Position = script.Parent.Parent.Door2.Position + Vector3.new(i, 0, 0) end wait(5) for i = 0, -0.3, -0.01 do script.Parent.Parent.Door1.Position = script.Parent.Parent.Door1.Position + Vector3.new(i, 0, 0) end for i = 0, 0.3, 0.01 do script.Parent.Parent.Door2.Position = script.Parent.Parent.Door2.Position + Vector3.new(i, 0, 0) end
|
|
|
| Report Abuse |
|
|
Damp
|
  |
| Joined: 05 Dec 2008 |
| Total Posts: 10086 |
|
| |
|