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 'Died'?

I made a GUI that pops up from outside the screen when a player dies but it shows this error when I die and doesn't work. Attempt to index nil with 'Died' I tried to change it to a server script but it showed the same error again so I put it back in a LocalScript.

Erroring line

Line 6

local frame = script.Parent.Frame
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")

humanoid.Died:Connect(function()
	frame:TweenPosition(
		UDim.new(0.256, 0,0.075, 0),
		"Out",
		"Quad",
		0.5,
		false
	)
	wait(3.5)
	frame:TweenPosition(
		UDim.new(0.256, 0,-1.075, 0),
		"Out",
		"Quad",
		0.5,
		false
	)
end)

LocalScript is stored inside of the ScreenGUI

ty if u helped

1 answer

✓ Accepted answer

".Character" haven't loaded in yet when you accessed it so humanoid will also be 'nil'. Give it some time.

Consider replacing line 3 and 4 to this:

local character = player.Character
repeat 
    wait()
    character = player.Character
until character ~= nil

local humanoid = character:WaitForChild("Humanoid")

1 comment

0

Thanks this helped now it works :D

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