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

1local player = game.Players.LocalPlayer
2local leaderStats = player:WaitForChild("leaderstats")
3local gold = leaderStats:WaitForChild("Gold")
4 
5gold:GetPropertyChangeSignal("Value"):Connect(function()
6    script.Parent.Text = "Gold"..tostring(gold.Value)
7end)
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:

01local player = game.Players.LocalPlayer
02local leaderStats = player:WaitForChild("leaderstats")
03local gold = leaderStats:WaitForChild("Gold")
04 
05--if you want to get the player's gold when they join as well
06script.Parent.Text = 'Gold: '..tostring(gold.Value)
07 
08gold.Changed:Connect(function()
09    script.Parent.Text = "Gold: "..tostring(gold.Value)
10end)

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

01game:GetService('Players').PlayerAdded:Connect(function(player)
02    local character = player.Character or player.CharacterAdded:Wait()
03    local humanoid = character:FindFirstChildOfClass('Humanoid')
04 
05    local leaderstats = Instance.new('Folder')
06    leaderstats.Name = 'leaderstats'
07    leaderstats.Parent = player
08 
09    local gold = Instance.new('IntValue')
10    gold.Name = 'Gold'
11    gold.Parent = leaderstats
12    gold.Value = 1
13 
14    --gives a player gold every second
15    while true do
16        wait(1)
17        gold.Value = gold.Value + 1
18    end
19end)
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