I have a GUI that gives a small effect to the player when adding coins, the issue is that using .Heartbeat:Wait() is not fast enough when using large numbers (like 100,000). What do I do from here?
Script:
local RS = game:GetService("RunService")
game.ReplicatedStorage.Events.CoinEffect.OnClientEvent:Connect(function(Coins)
local coinText = script.Parent
coinText.Text = "Coins: "..game.Players.LocalPlayer.inventory.Coins.Value - Coins
for i = game.Players.LocalPlayer.inventory.Coins.Value - Coins, game.Players.LocalPlayer.inventory.Coins.Value + Coins do
coinText.Text = "Coins: "..i
RS.Heartbeat:Wait()
end
end)
EDIT:
If you come across this article and plan on using tweens, ensure you use an IntValue as NumberValues give you decimals to the hundred thousandths
I don’t really see a difference between Heartbeat and RenderStepped. I have the step at 3 right now for the for loop, still pretty slow.
The issue is that the 1,000,000 coin package may be for sale for my game, so I don’t want people to have to wait so long for the text to stop changing. Do you think a formula may work for the step instead?
Perhaps use a NumberValue object and use the tween service on that object. You can then use GetPropertyChangedSignal on that object watching for the value to change and then update your UI accordingly with that value.
That way, you can set a tween as 1 second for example, so a tween from 1-10 or 1-1000000 will both take 1 second and look like it is incrementing up like you want.
Heartbeat:Wait() (or Stepped:Wait() or RenderStepped:Wait()) is the fastest you’re gonna get: 1/60th of a second.
Think of it this way: The client runs at 60 fps. If it counts faster than 60 fps, it is impossible to see numbers unless they appear on a frame. Incidentally, this is a perfect hint as to what you should do. @3rdhoan123 said it right - Don’t count 1 by 1. You can either do what @serverIess mentioned and use TweenService on a NumberValue and poll that value every heartbeat/frame, or you could do that manually by defining your own lerp function.
You shouldn’t jump by 1 instead you should use higher numbers. your best options are either to jump by prime numbers(so the lower digits dont stay the same) that scale as the number of coins the person gets scaled. Or you can jump by multiples of 10 that scale based on the amount of coins recieved but while that happens the lower digits are randomly shuffled to give the effect of coins gathering quickly