How do I only run a script if the player's humanoid exists?

So basically I want to change the character’s walkspeed, but sometimes it prints an error saying “Humanoid is not a member of character”

So I used an if statement to detect if it is

if player.Character.Humanoid then
	player.Character.Humanoid.WalkSpeed = 16
	player.Character.Humanoid.JumpPower = 50
end

But it still returned the same error. (But only sometimes)

How can I fix this?

1 Like

You can create a variable for the Character & Humanoid.

local character = player.Character or player.CharacterAdded:Wait()
local hum = character:FindFirstChild("Humanoid")

and check if hum exists. If the error still exists, what is the error?

4 Likes

If I do that, do I have to use and if statement to detect if “hum” exists?

Yes, if hum then

should work.