I wanted to make an elevator, it works perfectly fine but, when 2 players push at the same time on the button from the level 1 and the level 2 for example, the elevator get stuck at the bottom or the top
I can't figure out where does the issue is from here's the script
local Pressed = false script.Parent.ClickDetector.MouseClick:connect(function() repeat wait(1) until script.Parent.Parent.Parent.Parent.Elevator.Position.Y >= 17.5 -- maximum height or script.Parent.Parent.Parent.Parent.Elevator.Position.Y <= -57 -- minimum height wait(3) --supposed to be a cooldown before the elevator can react to the next call if not Pressed then Pressed = true repeat script.Parent.Parent.Parent.Parent.Elevator.Position = script.Parent.Parent.Parent.Parent.Elevator.Position + Vector3.new(0,0.2,0) wait(0.01) until script.Parent.Parent.Parent.Parent.Elevator.Position.Y >= 17.5 --inverted with -57 for the second button repeat script.Parent.Parent.Parent.Parent.Elevator.Position = script.Parent.Parent.Parent.Parent.Elevator.Position - Vector3.new(0,0.2,0) wait(0.01) until script.Parent.Parent.Parent.Parent.Elevator.Position.Y <= -57 --inverted too Pressed = false end end)
This script is situatued into a button, there's 2 of them, the second have exactly the same code exept for the value
Thank you in advance.
We can create a debounce with a BoolValue that will have to be located outside of these scripts
So let's assume that these button are located inside a model and along with them, there is a BoolValue instance with them.
local db=script.Parent.Parent.BoolValue --path to boolvalue local Pressed = false script.Parent.ClickDetector.MouseClick:connect(function() if db.Value==false then db.Value=true repeat wait(1) until script.Parent.Parent.Parent.Parent.Elevator.Position.Y >= 17.5 -- maximum height or script.Parent.Parent.Parent.Parent.Elevator.Position.Y <= -57 -- minimum height wait(3) --supposed to be a cooldown before the elevator can react to the next call if not Pressed then Pressed = true repeat script.Parent.Parent.Parent.Parent.Elevator.Position = script.Parent.Parent.Parent.Parent.Elevator.Position + Vector3.new(0,0.2,0) wait(0.01) until script.Parent.Parent.Parent.Parent.Elevator.Position.Y >= 17.5 --inverted with -57 for the second button repeat script.Parent.Parent.Parent.Parent.Elevator.Position = script.Parent.Parent.Parent.Parent.Elevator.Position - Vector3.new(0,0.2,0) wait(0.01) until script.Parent.Parent.Parent.Parent.Elevator.Position.Y <= -57 --inverted too Pressed = false end db=false end end)