I'm trying to make a sprint button with the shift button. When I hold down the left shift the message will not appear nor will the speed of my character change. What needs to be fixed?
(Ran in a local script)
local UserInputService = game:GetService("UserInputService") local isPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) if isPressed then repeat game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = RunningSpeed.Value until not isPressed game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = WalkingSpeed.Value end
Try:
local UserInputService = game:GetService("UserInputService") local isPressed = false local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() UserInputService.InputBegan:Connect(function(Input, GameStuff) if GameStuff then return end if Input.KeyCode == Enum.KeyCode.LeftShift then isPressed = true while UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and isKeyPressed do wait() Char.Humanoid.WalkSpeed = RunningSpeed.Value end isPressed = false Char.Humanoid.WalkSpeed = WalkingSpeed.Value end end) UserInputService.InputEnded:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then isPressed = false end end)
This might fix it
Hopefully, this helped.
Best Of Luck Developer!