Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I show leaderstats on a text label?

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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.

0
can you try explaining it? T3_MasterGamer 2189 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

@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)

Answer this question