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

How do i get Name of Humanoids parent?

I am trying to get the Humanoids Parents Name in the Following segment of code But it only gives me the error "attempt to index nil with 'Parent'" when i get up from the seat

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	humanoid = Seat.Occupant
	Character = humanoid.Parent
end)


(humanoid and Character were declared previously)

Thanks in Advance! This forum has been very helpful!

2 answers

I think it's because when you get up from the seat, Seat.Occupant becomes nil. Which means, there is no one on the seat. And obviously, nil has no parent or anything. Maybe you can do this instead:

Seat:GetPropertyChangedSignal("Occupant"):Connect(function(property)
	if property == nil then return end --checks if property is nil and basically stops the script if so. so it wouldnt error out
	
		humanoid = Seat.Occupant
    	Character = humanoid.Parent
end)

Hope this helps!

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