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

Script stops working after first attempt?

Asked by 6 years ago

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)

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

"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.

0
I tried adding BreakLoop = false in all places I can imagine, but it still won't work. Jxonathan 0 — 6y
Ad

Answer this question