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

How do I make a Text label display how much currency you have?

Asked by 3 years ago

I got this code from a YouTube tutorial

local player = game.Players.LocalPlayer
local leaderStats = player:WaitForChild("leaderstats")
local gold = leaderStats:WaitForChild("Gold")

gold:GetPropertyChangeSignal("Value"):Connect(function()
    script.Parent.Text = "Gold"..tostring(gold.Value)
end)
0
My value is an int value nicemorew 26 — 3y

2 answers

Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 years ago

So this is a pretty easy fix, just change :GetPropertyChangedSignal to .Changed.

Here's the code I typed up:

local player = game.Players.LocalPlayer
local leaderStats = player:WaitForChild("leaderstats")
local gold = leaderStats:WaitForChild("Gold")

--if you want to get the player's gold when they join as well
script.Parent.Text = 'Gold: '..tostring(gold.Value)

gold.Changed:Connect(function()
    script.Parent.Text = "Gold: "..tostring(gold.Value)
end)

I tested it in-game with this leaderstats script and it worked just fine for me:

game:GetService('Players').PlayerAdded:Connect(function(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:FindFirstChildOfClass('Humanoid')

    local leaderstats = Instance.new('Folder')
    leaderstats.Name = 'leaderstats'
    leaderstats.Parent = player

    local gold = Instance.new('IntValue')
    gold.Name = 'Gold'
    gold.Parent = leaderstats
    gold.Value = 1

    --gives a player gold every second
    while true do
        wait(1)
        gold.Value = gold.Value + 1
    end
end)
0
It worked but I don't really want the gold: thingy. nicemorew 26 — 3y
0
Not sure what you mean by that but if you don't want to use my code you can just changed the GetPropertyChangedSignal to .Changed on yours zane21225 243 — 3y
0
I don't want it to have Gold: 200 nicemorew 26 — 3y
0
Just change the text in the quotation marks on line 9 (in the first script) to whatever text you want zane21225 243 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I think you need to put this code in a LocalScript inside of a TextLabel.

1
Please post your answer as a comment instead. Soban06 410 — 3y

Answer this question