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

How do i get Name of Humanoids parent?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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!

Ad
Log in to vote
0
Answered by 2 years ago
Character = humanoid and humanoid.Parent

Answer this question