Money count only updating once

Hello!
I am working on a wallet tool. I have it pretty much done but i have one slight problem. It only updates the money count when i equip it. So when i earn money when I’m holding it it doesn’t update. How could i make it so it updates live?
This is my current code:

local player = game.Players.LocalPlayer

local countgui = script.Parent.EarnedDC

local tool = script.Parent.Parent

tool.Equipped:Connect(function()

countgui.TextLabel.Text = player.leaderstats.DogeCoins.Value

end)

Thanks in advance.

Try adding this to your script:

player.leaderstats.DogeCoins.Changed:Connect(function(value)
   player.leaderstats.DogeCoins.Value = value
end

The whole script should look like this:

local player = game.Players.LocalPlayer

local countgui = script.Parent.EarnedDC

local tool = script.Parent.Parent

player.leaderstats.DogeCoins.Changed:Connect(function(value)
   countgui.TextLabel.Text = value
end

tool.Equipped:Connect(function()

countgui.TextLabel.Text = player.leaderstats.DogeCoins.Value

end)
1 Like

I’m having the “ValueChanged is not a valid member of IntValue” error

My bad, just put “DogeCoins.Changed” not "DogeCoins.ValueChanged’

Oh wait I also wrote the script wrong. I edited the script I wrote before, you can try copying and pasting it again.

I changed it but now it does the same thing. It doesn’t update “live” for some reason

Can you show me an image of your new script please?

local player = game.Players.LocalPlayer

local countgui = script.Parent.EarnedDC

local tool = script.Parent.Parent

player.leaderstats.DogeCoins.Changed:Connect(function(value)
	countgui.TextLabel.Text = value
end)

tool.Equipped:Connect(function()

	countgui.TextLabel.Text = player.leaderstats.DogeCoins.Value

end)

Try changing

countgui.TextLabel.Text = value

to

countgui.TextLabel.Text = player.leaderstats.DogeCoins.Value

Also, are there any errors in the output?

2 Likes

This works now! Thanks alot for the help.

1 Like

No problem! :smiley:

(character limit)

local players = game:GetService"Players"
local tool = script.Parent --Reference to tool.
local billboardGui = tool.BillboardGui --Reference to tool's BillboardGui.

local connection

tool.Equipped:Connect(function()
	local character = tool.Parent
	if not character then return end
	local player = players:GetPlayerFromCharacter(character)
	if not player then return end
	local leaderstats = player:FindFirstChild"leaderstats"
	if not leaderstats then return end
	local stat = leaderstats:FindFirstChild"" --Change to stat's name.
	if not stat then return end
	billboardGui.TextLabel.Text = stat.Value
	if connection then
		if connection.Connected then
			return
		end
	end
	connection = stat.Changed:Connect(function(value)
		billboardGui.TextLabel.Text = value
	end)
end)

tool.Unequipped:Connect(function()
	if connection then
		if connection.Connected then
			connection:Disconnect()
		end
	end
end)

Pseudo-code.

Hi! It’s me again I’m having another issue that the Amount of coins is only showing for the player that is holding the tool, how could i fix this?

Since this was last replied to six days ago, for the sake of trying to get you a reply as quick as possible I’ll chime in.

This is most likely due to the fact you’re doing this locally. You’re going to want to completley handle this with a server script. I think Forummers reply here is really good as it takes into account for the fact that you want this done on the server side. Try putting a ServerScript with Forummers reply inside the tool. I see no reason why it wouldn’t work.

1 Like

Alright, i will try that. Thank you!

It doesn’t seem to be working and i have no errors. How could i fix this?

Nevermind! I accidentally put the script in ServerScriptService, I’m sorry! xD

1 Like