Problem With Level GUI

Hey Everyone! I have had a problem recently making my level system. So when I am trying to level up someone or it start a new level. It all works besides the GUI. Because since I don’t want to set the XP value to 0 it has the bar automatically filled to the half way mark or towards the end. I will provide the scripts and a video below. Also I’m new to scripting so the level system is quite horrible in organization. I’ve also tried many tutorials and reading other posts before deciding to check in with the fellow scripters.

VIDEO

https://gyazo.com/52f698b5975c92570f4a197910aee5bd

As you can see it fills up towards the end even on the new level I really do not like how that does it please help.

SCRIPTS

local LEVELS = {
	Level2 = 800,
	Level3 = 2100,
	Level4 = 3800,
	Level5 = 6100,
	Level6 = 9500,
	Level7 = 12500,
	Level8 = 16000,
	Level9 = 19800,
	Level10 = 24000,
	Level11 = 28500,
	Level12 = 33400,
	Level13 = 38700,
	Level14 = 44200,
	Level15 = 50200
}

local req2 = LEVELS.Level2

XP.Changed:Connect(function(Changed)
	if Changed then
		if XP.Value < LEVELS.Level2 then
			if XP.Value > LEVELS.Level2 then
			end
			XpBar:TweenSize(UDim2.new(XP.Value / req3, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.001)
		end
	end
end)

while wait() do
	
	-- LEVEL 2 --
	
	if XP.Value < LEVELS.Level2 then
		if XP.Value > LEVELS.Level2 then
		end
		XpTL.Text = XP.Value..' / '..LEVELS.Level2
		CurrentLevelTL.Text = Level.Value
		NextLevelTL.Text = Level.Value + 1
	end
end
local LEVELS = {
	Level2 = 800,
	Level3 = 2100,
	Level4 = 3800,
	Level5 = 6100,
	Level6 = 9500,
	Level7 = 12500,
	Level8 = 16000,
	Level9 = 19800,
	Level10 = 24000,
	Level11 = 28500,
	Level12 = 33400,
	Level13 = 38700,
	Level14 = 44200,
	Level15 = 50200
}

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild('leaderstats')
	
	
	leaderstats.XP.Changed:Connect(function()
		
		if leaderstats.XP.Value < LEVELS.Level2 then
			leaderstats.Cash.Value = leaderstats.Cash.Value
			leaderstats.XP.Value = leaderstats.XP.Value
			leaderstats.Level.Value = 1
		end
		
		-- LEVEL 2 --
		
		if leaderstats.XP.Value >= LEVELS.Level2 then
			if leaderstats.Level.Value <= 2 then
			end
			leaderstats.Cash.Value = leaderstats.Cash.Value
			leaderstats.XP.Value = leaderstats.XP.Value
			leaderstats.Level.Value = 2
		else
			leaderstats.XP.Value = leaderstats.XP.Value
		end
	end)
end)

Thank you guys! Have a great thanksgiving.

There isnt an if function that checks if the player has leveled up. (I think.)

if XP.Value > LEVELS.YourLevel then
    XP.Value = 0
    Level.Value = Level.Value + 1
end

And these functions will always be false if you put these inside another
if function that checks if XP.Value < LEVELS.Level2.

if XP.Value > LEVELS.Level2 then
end

Yeah I have it. I have it so if its equals to or greater then the value. I’m just struggling with the bar because I don’t want it set to zero after every level. And its broken because when I level up the bar is already near filled

I think the problem is that you are not using >= (greater or equals) or <= (less or equals).

if XP.Value >= LEVELS.YourLevel then
    -- do stuff
end
1 Like

No the levels are working just not the bar.