My progress bar is broken

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.

I think it should be basic first the medium for RanksName

This has nothing to do with my problem…

Also please note that the ‘‘error’’ is not only happening to this rank.
It is happening to ALL of them.

if no, then I don’t know :sweat_smile: :crazy_face:

Its starting in the middle because that’s approximately where the current XP would be, its always starting from 0 to 100% on the progress bar when you go from medium to basic the end goal is now 9999 but you are starting at 6500 not at 0 the begining of your progress bar so we would want to subtract the minimum amount of XP for that rank from your current XP to make it start from 0 on the progress bar

try doing this

	script.Parent.XpBar.BarHolder.Bar:TweenSize(UDim2.new((Xp.Value-RanksInfo.RanksXP[RankTier.Value][1])/RanksInfo.RanksXP[RankTier.Value][2], 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.35)

it should come out working after this
https://gyazo.com/630b01910ec39dec52babb952e465f34

script.Parent.XpBar.BarHolder.Bar:TweenSize(UDim2.new((Xp.Value-RanksInfo.RanksXP[RankTier.Value][1])/(RanksInfo.RanksXP[RankTier.Value][2]-RanksInfo.RanksXP[RankTier.Value][1]), 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.35)

maybe

Now the bar goes to ~24% and I get a new Rank.

Lol

I’ve tried this before and it doesnt work

Can you show me what you did, it is working for me and I am curious what the problem is

sorry for taking some time…

ok soo… the bar does the same thing but reversed
now it starts from 0, but ends at the middle

(ignore the % text)

can i see the edit to the script iself?

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][1])/RanksInfo.RanksXP[RankTier.Value][2], 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.35)
end
script.Parent.XpBar.BarHolder.Bar:TweenSize(UDim2.new((Xp.Value-RanksInfo.RanksXP[RankTier.Value][1])/(RanksInfo.RanksXP[RankTier.Value][2]-RanksInfo.RanksXP[RankTier.Value][1]), 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.35)

last try :sweat_smile:

It still doesn’t work lol, idk…