I'm making a door and I want it to check if the script is already running, and if it is then it will wait until the function is complete before running another function. I noticed the return command could be used somehow, but I wasn't sure how to use it and if it was the best way to tell the script to wait. When I click the OnDoor button once it works but when I click it multiple times the script runs at the same time as the other ones which haven't completed.
ButtonOff script
Door = game.Workspace.TDoor.TheDoor
ButtonOn = game.Workspace.TDoor.ButtonOn
function OffDoor()
Door.Transparency = 0
Door.CanCollide = true
ButtonOn.Material = Enum.Material.Plastic
end
script.Parent.ClickDetector.mouseClick:connect(OffDoor)
Button on script
Door = game.Workspace.TDoor.TheDoor
ButtonOn = game.Workspace.TDoor.ButtonOn
function OnDoor()
Door.Transparency = 0.5
Door.CanCollide = false
wait(0.5)
ButtonOn.Material = Enum.Material.Neon
wait(0.5)
ButtonOn.Material = Enum.Material.Plastic
wait(0.5)
ButtonOn.Material = Enum.Material.Neon
wait(0.5)
ButtonOn.Material = Enum.Material.Plastic
wait(0.5)
ButtonOn.Material = Enum.Material.Neon
wait(0.5)
ButtonOn.Material = Enum.Material.Plastic
wait(0.5)
ButtonOn.Material = Enum.Material.Neon
end
script.Parent.ClickDetector.mouseClick:connect(OnDoor)
