Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with "FindFirstChild"?

Asked by 1 year ago

I am making a localscript that is supposed to make the screen read on death, but when I try to check HealthChanged, it gives me this error.

Players.Uniplier.PlayerGui.Death.Death:3: attempt to index nil with 'FindFirstChild'

Here is my code.

local player = game:GetService("Players").LocalPlayer 
local char = player:FindFirstChild("Character")
char:FindFirstChild("Humanoid").HealthChanged:Connect(function()
    if char.charactervalues.Grabbed.Value == true then
        local death = script.Parent.Frame
        if char.Humanoid.Health <= 1 then
            death.Transparency = 0
        end
    end
end)
0
Where is this script placed and is this script suppose to open a gui frame?? theking66hayday 841 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago

I'm not sure if it is this, as I've never tried getting the character this way, but instead of doing player:FindFirstChild("Character"), I would recommend using player.Character or player.CharacterAdded:Wait(). If that isn't the problem then try using char:WaitForChild("Humanoid") because theres a chance that the character model shows up but the humanoid has not been loaded yet.

Ad

Answer this question