Hello,
I have created a function called openDoor() to open a sliding door when a button is clicked.
Now I would like to use the same function to open all the doors in my game using their respective buttons.
I'm assuming that button and door should be set as parameters in openDoor() and arguments should be passed when the event MouseClick trigger the function.
Based on my assumptions the arguments should be set to the specific "door" and "button" in my game.workspace that the player wants to open.
Unfortunately it doesn't work... The function for some reason is executed before the event MouseClick happens.
Any idea how to do it ?
Thank you in advance.
Best
local door1 = game.workspace.model.door1
local button1 = game.workspace.model.button1
local door5 = game.workspace.model.door5
local button5 = game.workspace.model.button5
openDoor(door, button)
-- change the status/color of the button
-- move the door
end
button1.ClickDetector.MouseClick:connect (openDoor(door1, button1))
button5.ClickDetector.MouseClick:connect (openDoor(door5, button5))

3 comments
Or you can call the function once but in the function you open the doors.
If you are needing help with scripting, you could let me know your skype or discord by PM'ing your name on roblox.
Thanks FireDusk! Really appreciated!