Attempt to index nil with 'Humanoid'

So i keep getting this error attempt to index nil with ‘Humanoid’ My script is inside starterpack and it’s a local script

 game.Players.LocalPlayer.Character.Humanoid.Running:Connect(function(speed)
 	if speed > 13 and script.Parent.Parent == game.Players.LocalPlayer.Character then
		script.Parent.Running:FireServer()	
        end
end)

You can try

local player = game.Players.LocalPlayer
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid") --The script will wait until Humanoid is found
Humanoid.Running:Connect(function(speed)

Instead of

game.Players.LocalPlayer.Character.Humanoid.Running:Connect(function(speed)

I figured it out, i just put a wait 2 sec and it worked

Thing is, the character has probably not loaded in yet. Instead of getting the character like that, do

local plr =  game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()

hm. I don’t recommend that. While it does work, it makes the script messy. Try what I did :slight_smile:

yeah i knew that but it still didn’t work when i put the CharacterAdded

What about Character:WaitForChild("Humanoid")?

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local remote = script:WaitForChild("Running")

humanoid.Running:Connect(function(speed)
	if speed > 13 then
		remote.Running:FireServer()	
	end
end)

You shouldn’t add arbitrary waits to scripts, if you need to wait for certain instances to load/replicate then do as I have in the above (this script will work near-instantly as opposed to 2 seconds after it executes).

This could fail, I suggest instead of waiting 2 seconds to do

  1. Wait for the Character (if its not already loaded)
  2. Find/Wait for the humanoid
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

Character:WaitForChild("Humanoid").Running:Connect(function(speed)
 	if speed > 13 and script.Parent.Parent == Character then
		script.Parent.Running:FireServer()	
	end
end)

Note, if you only use LocalPlayer.CharacterAdded:Wait() it probably will not work as the Character might already be loaded, so we use this as a safety net.