generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: connecting click function to two parts

Previous Thread :: Next Thread 
Damp is not online. 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
SummerEquinox is not online. SummerEquinox
Joined: 25 Jun 2013
Total Posts: 2088
18 Apr 2015 09:54 PM
function onClick()
--code
end


script.Parent.ClickDetector:connect(onClick)
script.Parent.Parent.GetToTheOtherDoor:connect(onClick)
Report Abuse
GreatOculus is not online. GreatOculus
Joined: 30 Aug 2009
Total Posts: 2103
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 is not online. 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 is not online. 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
GreatOculus is not online. GreatOculus
Joined: 30 Aug 2009
Total Posts: 2103
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 is not online. Damp
Joined: 05 Dec 2008
Total Posts: 10086
18 Apr 2015 10:32 PM
Ah okay, makes sense, thank you. :)
Report Abuse
Damp is not online. 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
GreatOculus is not online. GreatOculus
Joined: 30 Aug 2009
Total Posts: 2103
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
SummerEquinox is not online. SummerEquinox
Joined: 25 Jun 2013
Total Posts: 2088
18 Apr 2015 10:41 PM
script.Parent.ClickDetector.MouseClick:connect(onClick)
script.Parent.Parent.Door2.ClickDetector.MouseClick:connect(onClick)
Report Abuse
Damp is not online. 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 is not online. 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 is not online. Damp
Joined: 05 Dec 2008
Total Posts: 10086
19 Apr 2015 04:00 PM
bump
Report Abuse
Damp is not online. Damp
Joined: 05 Dec 2008
Total Posts: 10086
19 Apr 2015 04:16 PM
bump2
Report Abuse
Damp is not online. 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 is not online. Damp
Joined: 05 Dec 2008
Total Posts: 10086
19 Apr 2015 07:05 PM
b
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image