[Old Post] Add Currency system

[This post is old, nothing here reflects the way i program and make posts today]

I want a system in which the player earns coins and instead of updating everything at once, updating one at a time, but I tried several times, looked at the devhub, researched various solutions and nothinga

The problem is that CoinsToAdd (NumberValue) does not update, and always gives as 0 after currency gain
The script does not keep track of the coins, as the coin gain increases, it stores all earnings, and then updates, but that is not what happens.

Script is a LocalScript located inside TextLabel

plsfix

Script I wrote:

local player = game.Players.LocalPlayer
local Coins = player.leaderstats.Coins

script.Parent.Text = Coins.Value

local function Add()
	local GC = script.CoinsToAdd
	for ToAdd = 1, GC.Value do
		print("started")
		GC.Value = GC.Value -1
		script.Parent.Text = script.Parent.Text +1
		wait(0.5)

	end
end


Coins:GetPropertyChangedSignal("Value"):Connect(function()
	local oldMoney = Coins.Value
	local gived = Coins.Value -oldMoney
	local GC = script.CoinsToAdd

	if GC.Value >0 then
		Add()
	else
		GC.Value = 1
		Add()
		wait(1)
		GC.Value = GC.Value -1
	end
end)

You don’t need to write the whole code for me if you don’t want to, just give tips, and if this post is in the wrong category, let me know

did you try to do tonumber(script.Parent.Text +1)?

)

your missing a small piece on your “for” loop
“for” loop need three Arguments
Variable, Starting number and how much to add each time the loop runs

if i am not wrong if you dont write the 3th argument it counts as 1

1 Like

Oh yes your right I never use a for loop without the third argument so i must have forgot

No your loop is fine I just confused myself
Does the print statement below

for ToAdd = 1, GC.Value do

print?

Oh i see what happening I have to do something right now so ill just give you the fixed code

local GC = script.CoinsToAdd -- In future place your variables here just not ones that have stuff like .Value and such
local Coins = player.leaderstats.Coins

script.Parent.Text = Coins.Value

local function Add()
	local GC = script.CoinsToAdd
	for ToAdd = 1, GC.Value do
		print("started")
		GC.Value = GC.Value -1
		script.Parent.Text = script.Parent.Text +1
		wait(0.5)

	end
end


Coins:GetPropertyChangedSignal("Value"):Connect(function()
	local oldMoney = Coins.Value
	local gived = Coins.Value - oldMoney
        --local GC = script.CoinsToAdd the "Add" function can't see this variable
	if GC.Value >0 then
		Add()
	else
		GC.Value = 1
		Add()
		wait(1)
		GC.Value = GC.Value -1
	end
end)
1 Like

Nevermind, i giveup. It already annoyed me off a lot, I’ve been trying to make it work since last night.

your script dont worked, srry

So do you get any output at all? Put a print statement in the property changed signal and see if it is updating. Add it in multiple locations. Also, try adding breakpoints and see what the value of GC.Value is at multiple points.

It seems you’re subtracting the value in the NumberValue rather than adding to it. This should fix it:

GC.Value = GC.Value +1