Help with billboardGui

Hi everyone I have a problem, I made it where a billboard gui goes over a players head, which i got working, then i thought it would be cool to show the amount of levels a player has in the billboard gui, which i got working, the real problem is making it serverside, it is only client side, so how can i make this serverside.


-- location info: ReplicatedStorage, BillboardGui, Text lable name: statshow, and the local script is inside of the billboard gui, not in the text lable itself
local player = game.Players.LocalPlayer
local text2 = script.Parent.StatShower

while true do
	wait()
	text2.Text = "Levels: "..player.leaderstats.Levels.Value
end

Try this

local text2 = script.Parent.StatShower
local lvls = game.Players.LocalPlayer.leaderstats.Levels
text2.Text = "Levels: "..lvls.Value

lvls.Changed:Connect(function(newVal)
	text2.Text = "Levels: "..newVal
end)

This works, but i need it too be on the server so everyone can see it.

You can just use game:GetService("Players") -- this is "Player" btw Player:WaitForChild("leaderstats").Levels.Value then

where do i put this, do keep it in a local script or server script

If you want it to be serversided you can use this

game.Players.PlayerAdded:Connect(function(Player)
	local lvls = Player:WaitForChild("leaderstats").Levels
	local text2 = script.Parent.StatShower -- Change this to your BillBoard TextLabel Location
	text2.Text = "Levels: "..lvls.Value
	lvls.Changed:Connect(function(newVal)
	text2.Text = "Levels: "..newVal
   end)
end)

Alright, so when i load in the game it actually shows the starting number, but the number wont change when i level up, which is weird because you used a wait for child on the leaderstats part

video:
robloxapp-20220821-2129023.wmv (997.6 KB)

Place this Script inside StarterCharacterScripts

repeat task.wait() until script:FindFirstAncestorOfClass("Model")

local Players = game:GetService("Players")

local BillboardGui = script.Parent -- Just making the assumption - if wrong, fix it
local Text2 = BillboardGui.StatShower

local Character = BillboardGui.Parent
local Player = Players:GetPlayerFromCharacter(Character)
if not Player then return end

local leaderstats = Player:WaitForChild("leaderstats")
leaderstats:WaitForChild("Levels").Changed:Connect(function(newValue)
	Text2.Text = "Levels: " .. newValue
end)

I made sure to make a fix of the billboardgui location, still not working