Hi I have a problem, please help me.
local Power = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Power") local Char = game.Players.LocalPlayer.Character Char:WaitForChild("Humanoid") local function Set(Regen) if Regen == true then game.ReplicatedStorage.SetHealth:FireServer(Char, math.floor(100 + Power.Value/10), math.floor(100 + Power.Value/10)) else game.ReplicatedStorage.SetHealth:FireServer(Char,nil, math.floor(100 + Power.Value/10)) end end Power.Changed:Connect(function() Set(false) end) Char.Humanoid.Died:Connect(function() game.Players.LocalPlayer.CharacterAdded:Wait() Set(true) end)
PlayerScripts.HealthUp:3: attempt to index nil with 'WaitForChild'
You added Char
. Remove it and it should work fine
local Char = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
first make the character variable:
local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait()
and replace the character:waitforchild with:
local humanoid = Char:waitForChild("Humanoid",10)
or:
repeat wait() until Char:findFirstChildOfClass("Humanoid")
If you want a variable for the humanoid. Don't just do
Char:WaitForChild("Humanoid")
Instead, add "local Humanoid = " behind it.
local Humanoid = Char:WaitForChild("Humanoid")
If you want the script to wait until the player is loaded, I'm pretty sure
game.Loaded:Wait()
does that.