What's wrong with my leaderboard gui script?

I’m not sure what’s wrong with my script. When I use the same script on a different leader stat(Cash) it works. But not with Lvl.
Please help, have a great day.

Output:
Players.Rapideed.PlayerGui.BarGui.BackgroundBoarderFrame.LvlBoarderFrame.TextLabel.LocalScript:3: attempt to index nil with ‘Value’

Script:
while wait() do

local player = game.Players.LocalPlayer

script.Parent.Text = "Lvl: "..player:WaitForChild("leaderstats"):FindFirstChild("Lvl").Value

end

You’d have to also use WaitForChild on the Lvl value, also, it’s better if you use the Changed event for BaseValues in your case instead of a loop that changes the text since an event will run when a condition has been met, something like this

local player = game:GetService("Players").LocalPlayer

local stats = player:WaitForChild("leaderstats")
local level = stats:WaitForChild("Lvl")

script.Parent.Text = "Lvl: " .. level.Value

level.Changed:Connect(function(newVal)
	script.Parent.Text = "Lvl: " .. newVal
end)

Changed in the cause of BaseValues such as Intvalues, StringValues, etc, return the new value in the BaseValue it is connected to, hence why I use it there

It should work, but it doesn’t match. The error says
Infinite yield possible on 'Players.SilentSuprino.leaderstats:WaitForChild(“Lvl”)
And why does it work for cash but not lvl. It’s the same value and script, just different names.

Did you remember to insert something called Lvl in your leaderstats? That’s happenign beause it couldn’t find it, could be that or a typo

Check the spelling of the script.

Oh sorry it’s my fault I named it “Level” instead of “Lvl.” Thanks for your help, have a great day.

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like