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

Why does this attempt to index a nil value?

Asked by 8 years ago

Can someone tell me why this seat script give's the error attempt to index a nil value in output, I don't explain the script that much since it's pretty self-explanatory, but basically I am trying to make it print the username of whatever user is sitting.

Code:

script.Parent.ChildAdded:connect(function(child)
    if child:IsA("Weld") then
        local player = game.Players:FindFirstChild(child.Parent.Name)
        print("Username: "..player.Name)
    end
end)
1
FindFirstChild returns nil if it can't find what you're looking for. If there is no player in the game whose name is the child's Parent, you'll get nil. Nil does not have a name, so you can't print it out. Try printing child.Parent.Name first to see what you get. funyun 958 — 8y
0
Thanks. ISellCows 2 — 8y

Answer this question