I'm trying to create a hold shift to sprint script. But when I try to get the player's character it gives the error that's in the title. Here's the code:
--Local script
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character
local hum = player.Character:FindFirstChild("Humanoid")
local held = false
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
held = true
end
while held == true do
wait()
hum.WalkSpeed = 60
end
end)
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
held = false
end
end)

6 comments
character is nil
The script is running before the character loads in. You need to do player.CharacterAdded:Wait() , and it will wait for the character to load in then finish the script.
^^^ local char = player.Character or player.CharacterAdded:Wait()
so you guys are saying that the script is trying to check if the player's character is there so fast that it ran before they got to load in?
Exactly
So we play the waiting game