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 make a Text label display how much currency you have?

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)

1 comment

0

My value is an int value

2 answers

✓ Accepted answer

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)

4 comments

0

It worked but I don't really want the gold: thingy.

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

0

I don't want it to have Gold: 200

0

Just change the text in the quotation marks on line 9 (in the first script) to whatever text you want

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

1 comment

1

Please post your answer as a comment instead.

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