How do I make a GUI that shows the stats in your leaderstats?

I have a leaderstat script so whenever the player equips and using a gear it adds a point to the leaderboard, but I want it to show the leaderstats for the point on gui but my script won’t work:

while wait() do

local player = game.Players.LocalPlayer

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

end
2 Likes

You need to find the value of “Height.” Also, I would use a changed function instead of updating this every milisecond.

local player = game.Players.LocalPlayer
local height = player:WaitForChild("leaderstats"):FindFirstChild("Height")

script.Parent.Text = "Height: ".. height.Value

height.Changed:Connect(function(new_value)
script.Parent.Text = "Height: ".. new_value
end)

This updated script will work better performance wise.

4 Likes

Change that to

while true do
wait(0.1)
local player = game.Players.LocalPlayer
local leaderstats = player.leaderstats.Height

script.Parent.Text = "Hight: " .. leaderstats.Value
end

feel free to use that above.

1 Like

This script will crash you, never do a while do statement without a wait. Also, while do loops without breaking them are costly on performance. I would advise using the one I made.

1 Like

Yes! Don’t use a while loop needlessly. Always check to see if something can be connected to a :Changed() function before resorting to loops.

1 Like
local text_label = script.Parent
local plr = game.Players.LocalPlayer

plr:WaitForChild("leaderstats").Height.Changed:Connect(function(val)
	text_label.Text = "Height:  "..val
end)

text_label.Text = "Height:  "..plr:WaitForChild("leaderstats").Height.Value

Check it out

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.