Hello developers!
I have a very easy and simple question, but I’ve just fixed a lot of major bugs in my game, and my mind can’t work anymore.
What im trying to do?
I just made a Rank System for my game, and I want to make a progress bar that shows you how much you completed from the level. Something similar to Pet Simulator X.
What's the problem?
The progress bar is broken. The bar doesn’t show the true value. And this is something that has to do with math, but I just can’t solve that, as I said.
Look at the video and you’ll see how when you get to the next Ranks the bar just starts from the middle.
What I want to get?
I just want the Progress bar to show the correct value.
How the Rank-System works?
There is a value called Xp
which is increased by various actions.
A script changes another value called RankTier
when the player’s Xp
is smaller and greater than two numbers stored in a ModuleScript.
Scripts:
Local Script | Bar Script
local function Update()
wait(0.25)
local RankName = RanksInfo.RanksName[RankTier.Value]
script.Parent.RankName.Text = RankName
script.Parent.XpBar.BarHolder.Bar:TweenSize(UDim2.new(Xp.Value/RanksInfo.RanksXP[RankTier.Value][2], 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.35)
script.Parent.Precentage.Text = tostring(Xp.Value/RanksInfo.RanksXP[RankTier.Value][2]*100):sub(1, 2).."%"
end
Server Script | Updates the RankTier Value
local function updateRankTier(Player, Xp, RankTier)
for i, v in pairs(RanksInfo.RanksXP) do
if Xp.Value >= v[1] and Xp.Value <= v[2] then
Player:WaitForChild("stats").RankTier.Value = i
NameTagGui.RankText.Text = RanksInfo.RanksName[i]
end
end
end
Module Script | Ranks Info
local RanksInfo = {
RanksXP = {
[1] = {0, 499}; --Starter
[2] = {500, 2499}; --Noob
[3] = {2500, 6499}; --Medium
[4] = {6500, 9999}; --Basic
[5] = {10000, 14999}; --Pro
[6] = {15000, 19999}; --Expert
[7] = {20000, 29999}; --Cool dude
[8] = {30000, 39999}; --Champion
[9] = {40000, 54999}; --Elite
[10] = {55000, 69999}; --Master
[11] = {70000, 89999}; --Legend
[12] = {90000, 114999}; --Godlike
[13] = {115000, 129999}; --Impressive
[14] = {130000, 149999}; --Not a Noob
[15] = {150000, 174999}; --Almost Impossible
[16] = {175000, 199999}; --The Best
[17] = {200000, 229999}; --B)
[18] = {230000, 274999}; --Impossible
[19] = {275000, 319999}; --Hacker
[20] = {320000, 349999}; --Insane Hacker
};
RanksName = {
--just ranks name u dont care about them
};
};
---------------------------------------
return RanksInfo
If I forgot to add something or missed details, just tell me and I will fix.