EXP system gui not working

Hello! So I’m making my first exp system and its going VERY well. I ran into a horrible problem where the gui either goes WAY over the limit or way under the limit that I need it to be. I’ve spent an hour on this and still don’t know what’s wrong.

local bar = script.Parent.EXPBar
local text = script.Parent.EXPLabel

local plr = game.Players.LocalPlayer
local level = plr.LevelInfo.Level
local exp = plr.LevelInfo.Experience
local expNeeded =math.floor(7 * 1.3 ^ level.Value)

text.Text = exp.Value.." / "..expNeeded

bar:TweenSize(UDim2.new(expNeeded/level.Value, 0, .19, 0), "In", "Linear", 0.3)
exp.Changed:Connect(function()
	expNeeded = math.floor(7 * 1.3 ^ level.Value)
	text.Text = exp.Value.." / "..expNeeded
	
	bar:TweenSize(UDim2.new(expNeeded/level.Value, 0, .19, 0), "In", "Linear", 0.3)

end)

level.Changed:Connect(function()
	expNeeded = math.floor(7 * 1.3 ^ level.Value)
	text.Text = exp.Value.." / "..expNeeded

	local change = exp.Value / expNeeded
	bar:TweenSize(UDim2.new(change,0, .19, 0), "In", "Linear", 0.2)
end)

Why are you using the level Value here? wouldn’t it work WAY better using exp.Value?

bar:TweenSize(UDim2.new(exp.Value/expNeeded, 0, .19, 0), "In", "Linear", 0.3)

Still isn’t filling up the entire section. Its only filling up a certain amount.
https://gyazo.com/e9a8388d594edd887f1c21214fb0793f

This should work, it worked for me when I made this type of gui.

Doesn’t work for me :confused:

Here I see that you are putting your exp value as the X scale parameter within the UI:
:TweenSize(UDim2.new(expNeeded/level.Value, 0, .19, 0), "In", "Linear", 0.3)

UDim2.new(X,_,_,_)

Instead you would need a ratio. First you would need to know how much exp you’ve earned then how much is the max then you would see how many times the “Earned XP” can go into the “Max XP” by divding. So your math should look like this: EarnedXP/MaxXP. Therefore when updating your UI use:

UDim2.new(EarnedXP/MaxXP, 0, .19, 0)

So a full bar would be UDim2.new(1,0,.19,0)' and a half bar would be UDim2.new(0.5,0,.18,0)
So we would want our XSize to be 1 or “bar full” when we have reached our max xp value. Or half “0.5” when we have reached the half way point towards max exp.

Ex: EarnedXP = 5, MaxXP = 10 '

EarnedXP/MaxXP = 0.5

I hope this makes sense. Let me know how it works out for you.

Alright thanks took alot of brain cells to read this

1 Like

Thanks for the feedback. Now that I’m relooking at this I did take the long approach of explaining. In simple terms I could of just told you to that you should divide earnedXP/maxXP instead of expNeeded/level.Value. lol

Oh Alright thats would have been easier LOL

Let me now if it work. Hit me up with that solution check.

Ye, i gotta figure out how to check the max exp and the amount of exp LOL

Wouldn’t that be:
local exp = plr.LevelInfo.Experience (The amount the player has earned.)
local expNeeded = math.floor(7 * 1.3 ^ level.Value) (The amount to reach aka max)?

wait that was what i did at first, and it didnt work, it was too little

What I did for my system was determined the size of the bar, then did the bar size / the total XP to get a scale factor. Took that scale factor value and multiplied it by the XP that the player currently has and set that X value to the size.

That’s really confusing, mind toning it down a bit dumber please?

You’re using expNeeded/level.Value under the exp.Changed

Ok, I’ll bring in an example. Let’s say that the X size of the bar is 1, and the total XP for the level is 100, the scale factor is 1/100 (which is .01). Next, let’s say the player has an XP of 23, you take that current XP value of 23 and multiply the scale factor of 1/100 which will get you 23/100. Then, you’d set the X size of the bar to 23/100.

1 Like
local plr = game.Players.LocalPlayer
local level = plr.LevelInfo.Level
local exp = plr.LevelInfo.Experience
local expNeeded =math.floor(7 * 1.3 ^ level.Value)

local function updateBar()
	expNeeded = math.floor(7 * 1.3 ^ level.Value)
	text.Text = exp.Value.." / "..expNeeded

	local change = exp.Value / expNeeded
	bar:TweenSize(UDim2.new(change,0, .19, 0), "In", "Linear", 0.2)
end

updateBar()
exp.Changed:Connect(updateBar)
level.Changed:Connect(updateBar)

Interesting, that made it much easier to understand thank you.

What do the last three lines do?