every time the player holds down the key 1 i want the part to move and when the player stops holding the key i want the part to stop, i tried this but after the first attempt everything stopped working
TestPart = workspace.TestPart Player = game.Players.LocalPlayer Mouse = Player:GetMouse() local BreakLoop = false Mouse.KeyDown:Connect(function(key) print(key) if key == "1" then while wait(0.03) do if BreakLoop == true then break end TestPart.Position = TestPart.Position + Vector3.new(0,0,1) end end end) Mouse.KeyUp:Connect(function(key) print(key)--> Shows the key the player is triggered through the output if key == "1" then BreakLoop = true end end)
"BreakLoop" starts out as a false Boolean value, however when the event "KeyUp" occurs "BreakLoop" changes to true which in turn breaks the loop from the KeyDown event, however you did not set "BreakLoop" back to false so as a result the loop is instantly broken when the KeyDown event occurs.