Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my XP bar stuck on 0%?

Hey, I have an XP bar in which I want the XP goal to increase by the players level * 15 every time they level up. But the problem is that the bar just stays on the 0% mark and doesn't move at all.

Any ideas on how to fix it?, Thanks, Cuv

player = game.Players.LocalPlayer
l = player:FindFirstChild("leaderstats")
xvalue = l:FindFirstChild("XP")
levelv = l:FindFirstChild("Levels")
mathlevel = (levelv.Value * 15)
local PositionX = script.Parent.Position.X.Scale
local initX = script.Parent.Size.X

while true do 
wait(0.1)
local CurrentXP = xvalue.Value
local XPTarget = CurrentXP / mathlevel 
script.Parent.Size = UDim2.new( 0, XPTarget, 0, 15) 
script.Parent.Position = UDim2.new(0.5, -100, 0.9, -20)
end 

1 answer

✓ Accepted answer

You should use the .Changed function, here is an example, for your script:

player = game.Players.LocalPlayer
l = player:FindFirstChild("leaderstats")
xvalue = l:FindFirstChild("XP")
levelv = l:FindFirstChild("Levels")
mathlevel = (levelv.Value * 15)
local PositionX = script.Parent.Position.X.Scale
local initX = script.Parent.Size.X

levelv.Changed:connect(function(p) --p is the property that changed
if p.Name == "Value" then
xvalue.Value = xvalue.Value * 15
script.Parent.Size = UDim2.new( 0, XPTarget, 0, 15) 
script.Parent.Position = UDim2.new(0.5, -100, 0.9, -20)
end
end)

Hope this helped, and if it did, don't forget to accept the answer, it gives us both rep

2 comments

0

Perfect, thanks. Suppose it saves the script continuously looping aswell +1

0

I would up vote it but it seems I've lost 8 rep with that question

This discussion is preserved as it was. New answers, comments, and votes are closed.