Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui moves faster after pressing button a few times?

Asked by 4 years ago

I have a gui to move a certain direction. It works fine for the first few times i press the button, but after a few more times of pressing the button, it moves faster. Why?

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input) 
    while wait() do
        if uis:IsKeyDown(Enum.KeyCode.Left) then
            script.Parent.Position = script.Parent.Position - UDim2.new(0, 2, 0, 0)
            print(script.Parent.Position.X.Offset)
        elseif uis:IsKeyDown(Enum.KeyCode.Right) then
            script.Parent.Position = script.Parent.Position + UDim2.new(0, 2, 0, 0)
        end
    end
end)
0
The inputbegan event creates new while loops everytime you press a button ihatecars100 502 — 4y
0
is there a way to break the loop whenever it ends? supercoolboy8804 114 — 4y
0
like what cars said, just use the break function for loops to break it. Neon_isHere 100 — 4y

Answer this question