Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make currency adding animation not take so long?

Asked by 2 years ago
Edited 2 years ago

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.

0
try doing wait() instead of wait(0.00001), maybe that can help? PaleNoobs 37 — 2y
0
didnt work ScentedTrashCan 16 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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.

Ad

Answer this question