GUI above players head?

I want a leaderboard stat above my head and i have the script but i dont know how to display it above the players head

1 Like

There’s an object called BillboardGui that allows you to put floating GUI over an item. Add one to the player’s head and put a frame in it, containing a TextLabel with your stat.

You can adjust quite a lot of things pretty easily from there, I recommend you look into that object’s documenation: BillboardGui | Documentation - Roblox Creator Hub

yes i know that but i dont know how to find the players head.

Well, Player.Character.Head, simply. It’s the part of the character called Head. You make the billboard’s parent that part, and it’ll float over it.

1 Like

im sorry but im really new to scripting and dont know how to do that

What are you trying to do with the overhead gui exactly? Do you want it to appear on a player’s head upon joining?

Ah, so you don’t know how to get a player’s character? You can do that by getting the player in the player list and asking for “Character”. Example, if I played your game, you would have to do:

game.Players.Bladster94.Character.Head

If you are on a local script and want to get the one that is currently playing, you can do:

game.Players.LocalPlayer.Character.Head

ok but if its a local script it wont show up to anybody else, so will game.Players.Player.Character.Head
and also how do i make it appear upon joining

1 Like

True, in your case a local script won’t do, my bad.

I recommend having a copy of your billboard ready somewhere, and use the CharacterAdded event to know when his avatar spawns.

local Billboard = game.ServerStorage.Billboard

local function OnCharacterAdded(character)
	local board = Billboard:Clone()
	board.Parent = character:WaitForChild("Head")
end

local function OnPlayerAdded(player)
	player.CharacterAdded:Connect(OnCharacterAdded)
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)

This assumes that you have a sample billboard ready in the game’s ServerStorage, and every time a player has his character spawning, it will put a copy of it over the player’s head.

Edit for precision: I made my version a bit more lengthy than necessary, but that way you can easily see what does what and add your own twist if you want to.

4 Likes

First, we will need an event that detects when a players join the game.

game:GetService("Players").PlayerAdded:Connect(function(player) --Detects when a player joins
		--Command here
	end)
end)

To get the player’s character, we will need an event that fires when a player’s character spawns.

game:GetService("Players").PlayerAdded:Connect(function(player) --Detects when a player joins
	player.CharacterAdded:Connect(function(character) --Gets the player's character
		local head = character.Head
		--Command here
	end)
end)

Assuming you have a copy of the GUI in ServerStorage

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        local clone = game:GetService("ServerStorage").OverheadGUI:Clone() -- Change OverheadGUI to whatever you've named the BillboardGui
        clone.Parent = player.Character.Head
    end)
end)

aS @Bladster94 mentioned, you can just parent the GUI to the player’s head. The easiest way to do this is to run a Script as a child of the player, via StarterCharacterScripts, that auto-creates, and parents it to the player’s head.

I previously used a system that just copied a GUI from ServerStorage, however, doing this is much easier, especially with leaderstats. The only caveat is having to keep a copy of the player’s leaderstat in SeverStorage.

Something like this:

local GUI = Instance.new("BillboardGui")
local Text = Instance.new("TextLabel")

GUI.StudsOffsetWorldSpace = Vector3.new(0,2,0)
GUI.Size = UDim2.new(5,0,1.5,0)
GUI.MaxDistance = 40

Text.Size = UDim2.new(1,0,1,0)
Text.Text = "Test" -- In your case, you can access the player's leaderstats via ServerStorage, because it's regular script, not a LocalScript. I reccomend you always keep a copy of leaderstats in ServerStorage to combat exploiters.

GUI.Parent = script.Parent.Head
Text.Parent = GUI
2 Likes

Creating the BillboardGui via script might be over complicating it, seeing as you’ll probably be designing it live first.

1 Like

No, because as the OP mentioned, they want it to display leaderstats. Copying it is ineffective, as you’d have to change it after it spawns it, a previous DevForum post mentioned this was bad practice, because it can hurt performance.

1 Like

Use a Surface GUI and use a script to change the text to the leaderboard Value it is possible.

1 Like

You’re right about that, but it might be a bit too bothersome for someone who just started with scripts to have to rewrite every property one by one.

2 Likes

That’s definitely true, but it’s always good practice for beginners. For this use case, this is the best method I can think of, but it’d be much easier for the OP to just copy a pre-made one.

2 Likes

I would’ve used GetPropertyChangedSignal and connect it to changing an aspect of the BillboardGui to the new value, personally.

1 Like

Looking through this thread, I see some code samples that have redundancy.

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local BillboardGui = ServerStorage:WaitForChild("BillboardGui")

local function OnPlayerAdded(PlayerObject)
    local Character = PlayerObject.Character or PlayerObject.CharacterAdded:Wait()
    if Character then
        local Head = Character.Head
        local BillboardGuiClone = BillboardGui:Clone()
        BillboardGuiClone.Parent = Head
    end
end

Players.PlayerAdded:Connect(OnPlayerAdded)

This code will directly reference the player’s character upon joining, otherwise it will wait for the character added event to fire for that player which will return the player’s character object. I personally prefer this method because it’s redundant to create multiple connections and functions when it can be done with one.

6 Likes