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)
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)
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
Wait for the Character (if its not already loaded)
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.