So, I recently got the motivation and started working on a new game I'm making. I want it to have a sprinting feature, but I can't seem to figure out what is the problem here.
I also followed a tutorial, YouTube link here: https://youtu.be/4z1HVwe0sLE
So I looked in another post in scriptinghelpers, and I found this; https://scriptinghelpers.org/questions/81021/hey-how-do-i-get-character-from-player-in-a-local-script
I followed the answer that someone posted and put it in my variables, but it still wouldn't work.
Here is the code snippet:
UserInputService = game:GetService("UserInputService")
local LShiftPressed = false
local Player = game.Players.LocalPlayer.Character
local Humanoid = Player.Humanoid
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
LShiftPressed = true
while LShiftPressed == true do
wait()
Humanoid.WalkSpeed = 32
game.Workspace.Sound.Sprint:Play()
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
LShiftPressed = false
while LShiftPressed == false do
wait()
Humanoid.WalkSpeed = 16
end
end
end)
Thank you if you have any feedback. Sorry if this code appears messy.

1 comment
I tried WaitForChild() and FindFirstChildWhichIsA() on the "Humanoid" variable but it still didn't work.