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.

3 comments
It work even better but when 2 players spam the button 1 and 2 the elevator get stuck again I have no idea from where does this thing come from
@Louix27626 Then make it so that these two buttons check towards the same BoolValue. Like the entire shaft's buttons check at the same boolvalue
Thank you so much <3