Ad
Log in to vote
1

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

Asked by 2 months 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 24 — 2mo

2 answers

Log in to vote
0
Answered by
zane21225 203 Moderation Voter
2 months 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 24 — 2mo
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 203 — 2mo
0
I don't want it to have Gold: 200 nicemorew 24 — 2mo
0
Just change the text in the quotation marks on line 9 (in the first script) to whatever text you want zane21225 203 — 2mo
Ad
Log in to vote
0
Answered by 2 months 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 390 — 2mo

Answer this question