I've been trying to make it so if the player continues to hold down left shift, there speed will continuously increase. Just can't seem to get it to work. If I hold down left shift the playerSprintSpeed stays the same, even though when i'm printing the speed it goes up. I'm a total noob when it comes to roblox scripting so any help is appreciated. Thanks!
local player = game:GetService("Players").LocalPlayer local character = player.Character local UserInputService = game:GetService("UserInputService") local defaultSpeed = 16 local leftShift = Enum.KeyCode.LeftShift local leftShiftDown = false local playerSprintSpeed = 16 UserInputService.InputBegan:Connect(function(key) if key.KeyCode == leftShift then character.Humanoid.WalkSpeed = playerSprintSpeed leftShiftDown = true end end) UserInputService.InputEnded:Connect(function(key) if key.KeyCode == leftShift then character.Humanoid.WalkSpeed = defaultSpeed print(character.Humanoid.WalkSpeed) end end) while wait() do if leftShiftDown then print("yes...") playerSprintSpeed = playerSprintSpeed + 1 print(playerSprintSpeed) else print("no...") end end
It's because your "playerSprintSpeed" is 16, the same as "defaultSpeed". Though I think something like this would work better
local uis = game:GetService('UserInputService') local plr = game.Players.LocalPlayer repeat wait() until plr.Character local playerSprintSpeed = 32 local defaultSpeed = 16 while wait() do if uis:IsKeyDown(Enum.KeyCode.LeftShift) then plr.Character.Humanoid.WalkSpeed = playerSprintSpeed else plr.Character.Humanoid.WalkSpeed = defaultSpeed end end