How would I be able to remove the unconditioned loop from the following run script?
My concern with the
while loop is that it requires a
wait to prevent it crashing resulting in the script not stopping you running immediately. It is almost unnoticeable in this example, however I also know that using
wait is a bad habit to fall into especially on more critical scripts.
local UserInputService = game:GetService("UserInputService") local KeyLShift = Enum.KeyCode.LeftShift local KeyRShift = Enum.KeyCode.RightShift local ShiftHeld function InputStart(InputObject) -- A key has been pressed if InputObject.KeyCode == KeyLShift or InputObject.KeyCode == KeyRShift then ShiftHeld = true while ShiftHeld == true do game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 300 -- Runspeed wait() end end ShiftHeld = false end UserInputService.InputBegan:Connect(InputStart)
Run.rbxl (17.7 KB)