Player level not showing on billboardgui

I made a billboardgui and put a script in serverscriptserver but when i try setting the value to the players level it doesn’t work, how do i fix that?


--Variables
local rep = game:GetService("ReplicatedStorage") --You can change this to ServerStorage for more security.
local nametag = rep.NameTag 

--Functions
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		--Varibles
		local head = char.Head
		local newtext = nametag:Clone() --Cloning the text.
		local NameText = newtext.Dude
		local LevelTitle = newtext.Level
		local humanoid = char.Humanoid
		
		humanoid.DisplayDistanceType = "None"
		
		--Main Text
		newtext.Parent = head
		newtext.Adornee = head
		NameText.Text = player.Name --Changes the text to the player's name.
		LevelTitle.Text = player.leaderstats.Level.Value --This is that the text will say.
		LevelTitle.TextColor3 = Color3.fromRGB(255, 255, 255) --This is what the color of the text will be.
	end)
end)

This will only set the value when the characteradded event is fired…when the character is…added.
If you want it to update regularly you will have to setup either an event or looped code function to do so, eg:

spawn(function()
   while player.Character and player.Character:FindFirstChild("Head") do
        LevelTitle.Text = player.leaderstats.Level.Value
        wait(3) --how often it will update
   end
end)

OR, better imo

player.leaderstats.Level.Changed:Connect(function()
    LevelTitle.Text = tostring(player.leaderstats.Level.Value)
end)

TYSM, it works

1 Like