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.
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