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

Why isn't this BillboardGui displaying content?

Asked by 8 years ago

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!

2 answers

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

Your Problem

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.

The Solution

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)
0
Is there anyway to make it to where the Gui does not expand when the Camera'sdistance increases? KingLoneCat 2642 — 8y
0
I don't know of any easy way to do it, sorry :( BlackJPI 2658 — 8y
Ad
Log in to vote
0
Answered by
yoshi8080 445 Moderation Voter
8 years ago

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.

0
Well it won't even appear atm KingLoneCat 2642 — 8y
0
I would recommend you use Instance.new to make your gui. yoshi8080 445 — 8y
0
Alright, thank you. KingLoneCat 2642 — 8y

Answer this question