The script works fine but when you click the the button rapidly it starts to move out of place.
Is there anything i can do to stop this happening?
local model = game.Workspace["Gate2"]; -- The model you want to move up local increment = 0.5 --The amount you want it to go up by each time local max = 10 --The studs you want to go up by local Button = script.Parent.ClickDetector --Change this to the ClickDetector. local closed = true; function onClick() if closed then move = increment else move = -increment end closed = not closed for i=1, max/increment do model:TranslateBy(Vector3.new(0,move,0)); wait(1/60) end end Button.MouseClick:connect(onClick) ;
You can use a debounce system. Here's the code that should work:
local model = game.Workspace["Gate2"]; -- The model you want to move up local increment = 0.5 --The amount you want it to go up by each time local max = 10 --The studs you want to go up by local Button = script.Parent.ClickDetector --Change this to the ClickDetector. local closed = true local isMoving = false function onClick() if isMoving == false then isMoving = true if closed then move = increment else move = -increment end closed = not closed for i=1, max/increment do model:TranslateBy(Vector3.new(0,move,0)); wait(1/60) end isMoving = false end end Button.MouseClick:connect(onClick) ;