Hello, I was trying to set the player’s default walkspeed
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local player = Players.LocalPlayer
local sprintspe = 16
local walkspe = 9
player.Character.Humanoid.WalkSpeed = walkspe
however, I was met with
Players.SkyRiseTH11650.PlayerScripts.LocalScript:10: attempt to index nil with 'Humanoid'
Try putting a variable with value as player.Character or player.CharacterAdded:Wait() as if there were no character found (the first value were false or nil), it’ll switch to the second one which is waiting for an event to return the character first, thus should not throw an error.
If you ask why can’t you put only player.CharacterAdded:Wait(), it is because there are still chances that the character managed to load in, and it will wait indefinitely as it did not register the event in time before it fired.
local character = player.Character or player.CharacterAdded:Wait()
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 16