Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to index nil with "FindFirstChild"?

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)

1 comment

0

Where is this script placed and is this script suppose to open a gui frame??

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.