XP progress bar doesn't work

I want to create an XP progress bar but my code doesnt work for some reason here it is

local plr = game.Players.LocalPlayer
local st = plr:WaitForChild("stat")
local leaderstats = plr:WaitForChild("leaderstats")
local level = leaderstats.Level
local xp = st.XP
local bar = script.Parent







xp.Changed:Connect(function()
		if level == 0 then
			local CurrentXP = xp.Value
			local nextlevelXP = 100 ---- xp required for next level
			local procentXP = (CurrentXP / nextlevelXP)
			bar.Size = UDim2.new ( procentXP, 0, 0.949, 0 )
			print(procentXP)
			bar:TweenSize(
				UDim2.new(procentXP, 0, 0.949, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Linear,
				.5
			)
			print("xp changed")
		end
	end)

Help is appreciated
I tried a while true do loop but that didnt seem to work either.

2 Likes

What part doesn’t work? Is it the Changed function? What’s not working, you’ve given me not a lot of data, so it’s hard to help you.

1 Like

The bar itself doesnt resize, sorry my brain is not really working I had a lot of code to write

The script has errors and is not even complete

I got no errors though… so thats why im here

this mean the script will run only if the player has level 0

yeah well thats the point, only do this calculation if the person is at no level

Well did the script print this stuff

1 Like

No, even though people start at level 0 it didnt print unless i put it in another function that didn’t fire when changed but that still didnt resize the bar

… clearly i forgot level.Value… ops sorry

1 Like