Currency count on join

Hi I want to make a currency count in join.
Just like this:


I have done a lot of research I couldn’t find anything on this subject. I did find and studied a comma gui currency script. Only I still need this above. I would appreciate it if I got help.

1 Like

What do you mean by this? Could you provide an example of a use case that would use what you’re trying to explain

Edit: Do you mean just playing that sound when a player joins? If so, just put it as a Sound instance where a localscript can reach it and run some code in a localscript that waits for the player, and if you want, character to be loaded in the server and play the sound to them

1 Like

I assume you mean you’d like to play a sound effect when they join? Could you please elaborate on your script and help needs more?

1 Like

I see what you’re talking about. I think how you’d want to do this is you make a PlayerAdded: function and then you make a for loop or a tween that counts all the way to the player’s current data. What you need to acomblish this is DataStores and (I could be wrong) Tweening

1 Like

No that effect when you enter the game and it counts from 0 to your current currency super fast.

Then what you do is, I’m guessing you have a Datastore set up, load the value of the Currency for the player in a value and use a for loop to go up by one till it reaches the data that the player has, playing the coin sound each time

1 Like
local Players = game.Players.LocalPlayer

local numbermine = Players.leaderstats.Energy

local Text = script.Parent.Parent.Amount.Text

local Start = 0

function addComma(number)

local left, num, right = string.match(number, '^([^%d]*%d)(%d*)(.-)$')

return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right

end

local numbermineComma = addComma(tostring(numbermine.Value))

for Text = Start, numbermineComma do

print("working")

end
```

I tried this, but it doesn't work. I also got the error: Players.OfficialAjoeb.PlayerGui.MainGui.StatsFrame.Energy.Amount.LocalScript:10: invalid 'for' limit (number expected, got string)

I think what you can do is to have a tick system in a loop that changes a wait( ) method to become shorter and shorter synchronizing it with your sound effect.

The money can depend on the Local Player’s balance which would require the usage of a data storage.

and this whole function can be added to a PlayerAdded( )

Hope this helps =)

What is this code supposed t odo?

1 Like

A script that counts from 0 to the current currency leaderstats of player in a textlabel with commas after every 3 letters, so for example 1000 becomes 1,000.

Shouldn’t it be

for num = Start, numbermine.Value do

Firstly you’re overwriting your Text variable, and also numberminecomma is a string, not a number

Edit: That’s not really how you’d do that, maybe try

for num = Start, numbermine.Value do
    Text.Text = addComma(tostring(num))
end

Changing the text variable to

local Text = script.Parent.Parent.Amount
1 Like

I tried that. It doesn’t count from 0 to the current leaderstats currency. It only shows the amount you have with that comma.

Wait what do you mean by that?

1 Like

For example, you have 1250 energy. When you enter the game it shows 1,250. It does not count 0 to 1,250 it shows directly the amount 1,250.

1 Like

Then there needs to be a wait in the code to delay it by a bit, in your code near the variables, add this

local run = game:GetService("RunService")

Then i nthe loop

for num = Start, numbermine.Value do
    Text.Text = addComma(tostring(num))
    run.Heartbeat:Wait()
end

I am unsure if the new APIs are enabled so you have to use the deprecated Heartbeat event to wait a frame

1 Like

Thank you so much! It’s working. How do I want it to count faster? And if the energy value has changed, the text will not change. Can I make that so it will change?

1 Like

If you want it to count faster, since Heartbeat is the fastest way to do that, so just do

for num = Start, numbermine.Value, 2 do

This way it will count up by 2 instead of 1.

And for changing the text when energy changes, just add this code before the loop

numbermine.Changed:Connect(function(val)
    Text.Text = addComma(tostring(val))
end)
1 Like

I puted this before the loop and now counting no longer works.

This worked

1 Like

If it didn’t work before the loop, then I think you can try putting it after it does the counting

1 Like
local Players = game.Players.LocalPlayer

local numbermine = Players.leaderstats.Energy

local Text = script.Parent.Parent.Amount

local Start = 0

local run = game:GetService("RunService")

function addComma(number)

local left, num, right = string.match(number, '^([^%d]*%d)(%d*)(.-)$')

return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right

end

local division = numbermine.Value / 10

for num = Start, numbermine.Value, division do

Text.Text = addComma(tostring(num))

run.Heartbeat:Wait()

end

numbermine.Changed:Connect(function(val)

Text.Text = addComma(tostring(val))

end)

Thank you so much! It worked. I have one last question. How can I change the count up to the players currency divided by 10. For example, someone with 1000 energy goes the count up always 1000/10 = 100. I’ve already tried something in the script above, but then the counting doesn’t work anymore. I hope you can help me.

1 Like