Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my XP bar stuck on 0%?

Asked by
Cuvette 246 Moderation Voter
8 years ago

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

Log in to vote
2
Answered by
xuefei123 214 Moderation Voter
8 years ago

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

0
Perfect, thanks. Suppose it saves the script continuously looping aswell +1 Cuvette 246 — 8y
0
I would up vote it but it seems I've lost 8 rep with that question Cuvette 246 — 8y
Ad

Answer this question