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.
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
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
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
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( )
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.
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?
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.