Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I show leaderstats on a text label?

Sorry, my last post was really poor

I'm trying to make a clicker game with my friend where you gain multiple stats. I want the speed stat to show on screen with a text label

while wait (0.01) do
script.Parent.Text = "Speed: "..game.Players.LocalPlayer.leaderstats.speed.Value
end

Why isn't this working?

2 answers

✓ Accepted answer

Try this instead

local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local speed = leaderstats:WaitForChild("speed")

script.Parent.Text = speed.Value
speed.Changed:connect(function()
	
	script.Parent.Text = speed.Value
	
end)

Make sure you put this code in a LocalScript. Then put the LocalScript inside the TextLabel.

1 comment

0

can you try explaining it?

@MajorMajesticPie's answer is correct, but I just want to change something.

local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local speed = leaderstats:WaitForChild("speed")

script.Parent.Text = speed.Value
speed.Changed:Connect(function(changedPropertyName)
	if changedPropertyName == "Value" then
		script.Parent.Text = speed.Value
	end
end)

Alternatively, you can use the player's humanoid walkspeed.

local function waitForChildWhichIsA(className, instance)
	local found = nil
	
	repeat
		task.wait()
		found = instance:FindFirstChildWhichIsA(className)
	until found ~= nil
	
	return found
end)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = waitForChildWhichIsA("Humanoid", character)

script.Parent.Text = humanoid.WalkSpeed
humanoid.Changed:Connect(function(changedPropertyName)
	if changedPropertyName == "WalkSpeed" then
		script.Parent.Text = humanoid.WalkSpeed
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.