Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make currency adding animation not take so long?

Hello, I have a game that multiplies the amount of kills that you get by 100, which is your XP score. So when the match ends, the user gets awarded XP based on the amount of kills they have, and it works. However I also have the level bar play a little animation as it gives you the XP earned by one, but it takes forever to finish, especially if one got a lot of kills. How can I make this animation be faster? I think I am doing it wrong but I am not a professional coder and I used this method as it was the most easiest one that I could code. Here is my code:

					local reward = cash
					local rewardxp = xp

					leaderstats.Cash.Value = leaderstats.Cash.Value + reward
				
					local total = leveling.Current.Value + rewardxp
				
					print(total)
				
				repeat tracker = tracker + 1 leveling.Current.Value = leveling.Current.Value + 		1 wait(0.00001) until tracker == total
				
				end

I could increase the increment value but if the increment value is not a multiple of the total, the loop will repeat forever, giving the player a lot more XP than needed.

2 comments

0

try doing wait() instead of wait(0.00001), maybe that can help?

0

didnt work

1 answer

I was able to fix it using the following formula:

local increment = 0
local recommended = 24400

repeat increment = increment + 347 print(increment) wait() until increment >= recommended
if increment >= recommended then
	local difference = increment - recommended
	print(difference)
	increment = increment - difference
	print(increment)
end

this system adds it by any increment value, and if it detects if the increment is greater than recommended, it subtracts how much it went past recommended, making the value equal to recommended.

This discussion is preserved as it was. New answers, comments, and votes are closed.