How to identify players models?

I am trying to insert a BillboardGUI into a players head when they join, but I don’t know how to address the new players model. Here is my attempt:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
       local label = Instance.new("BillboardGui", player.Character)
       local text = Instance.new("TextLabel", label)
end)

Using “player.Character” was a complete guess and unsurprisingly it didn’t work.

1 Like

After player is added, player.Character is not guaranteed to exist in the first place. Connect a function to player.CharacterAdded.

2 Likes

The thing that @Operatik said would look like this:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
       player.CharacterAdded:Connect(function(character)
             -- I would clone a template of the Gui here since it would be easier to customise.
             local label = Instance.new("BillboardGui", character)
             local text = Instance.new("TextLabel", label)
       end)
end)
1 Like

Also, it’s not recommended to use the second argument of Instance.new

Oh thanks, I was trying to figure out how to implement it. I’m very new to this, great help thanks guys :+1:

1 Like

Well that is true. I just copied the old code and inserted it into mine. I would normally set Parent at the end of messing around with the Instance.

That is true, look on DevForum for more articles about that. Example: PSA: Don't use Instance.new() with parent argument

2 Likes

Oh, that is my bad. I didn’t see this article before, sorry about that :sweat:

1 Like