So I am making a BillboardGui
and I am making a name BillboardGui
so, I don't want the BillboardGui
to expand when the camera's distance is farther away from the BillboardGui
and I thought what if I parent the BillboardGui
to the Player
when he enters the server and I set the Adornee
property to the players head.... However, the BillboardGui
gets cloned and parented to the correct place alright... BUT! Nothing is showing above the Character's head -_- Can anyone please help me with this? It would be greatly appreciated Oh! I almost forgot... The BillboardGui
has a Frame
under it which has a TextLabel
under it and the BillboardGui
is under a ServerScript
inside of ServerScriptService
and I am making it clone that and parent it to the PlayerGui
and I am trying to make a name Gui above a players head and I don't want the BillboardGui
to expand when the camera's distance increases....
Well I think I have elaborated enough for you guys, some help would be appreciated!
OUTPUT ERRORS:
16:42:05.939 - ServerScriptService.Script:6: attempt to index field 'Character' (a nil value)
16:42:05.940 - Stack Begin 16:42:05.940 - Script 'ServerScriptService.Script', Line 6 16:42:05.940 - Stack End
local gui = script:WaitForChild("BillboardGui") local clone = gui:clone() game.Players.PlayerAdded:connect(function(player) clone.Parent = player.PlayerGui clone.Adornee = player.Character.Head clone.AbsoluteSize = UDim2.new(0, 200, 0, 50) clone.AbsolutePosition = UDim2.new(0,0) clone.Frame.TextLabel.Text = player.Name end)
Thank you for reading all the way :D!
The error code that was returned tells you that player.Character = nil
. The most likely cause for this is that the Player was added before the Character. This would mean that player.Character
had not been set to any value yet and returns to you nil
.
We can use an event of Player called CharacterAdded
in order to apply the GUI onto the Character as soon as it's created:
local gui = script:WaitForChild("BillboardGui") local clone = gui:Clone() game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) clone.Parent = player.PlayerGui clone.Adornee = player.Character.Head clone.AbsoluteSize = UDim2.new(0, 200, 0, 50) clone.AbsolutePosition = UDim2.new(0, 0, 0, 0) clone.Frame.TextLabel.Text = player.Name end) end)
Here's a way to fix the expanding BillboardGui:
1. Go to your frame or text position for your BillboardGui that you're cloning
2. Change the position to {0,0}{0,-35} (The numbers can be changed to your preference, but leave -35 to any negative number of your choice.)
If this helped, please upvote this.