I have an Experience Bar script that I wrote, and it's really been bugging me. For some reason, it sets the bar to size 200 for practically every experience value OTHER than 0. If I set it to 0, the Size is correct, but if I set it to, for example, 50, the size is 200. What is wrong with it?
wait(2) local xps = {0, 3, 6, 10, 15, 20, 25, 30, 40, 50, 65, 80, 95, 110, 125, 140, 155, 180, 210, 250, 300, 350, 400, 450, 500, 575, 650, 725, 825, 1000}; Player = game.Players.LocalPlayer function hudsize() repeat wait() until Player and Player.leaderstats local ExpBar = script.Parent.ExpBar local xp = Player.Exp.Value local level = Player.leaderstats.Level.Value local required = math.ceil(xp/(xps[level+1] * 100)) if level < 30 then wait(.2) ExpBar.Size = UDim2.new(0, 15, 0, (required * 200)) elseif level >= 30 then wait(.2) ExpBar.Size = UDim2.new(0, 15, 0, 200) end end Player.Exp.Changed:connect(function() hudsize() end)
wait(2) local xps = {0, 3, 6, 10, 15, 20, 25, 30, 40, 50, 65, 80, 95, 110, 125, 140, 155, 180, 210, 250, 300, 350, 400, 450, 500, 575, 650, 725, 825, 1000}; Player = game.Players.LocalPlayer function hudsize() repeat wait() until Player and Player.leaderstats local ExpBar = script.Parent.ExpBar local xp = Player.Exp -- You can't or rather, shouldn't have .Value local level = Player.leaderstats.Level -- same here if level.Value < 30 then -- edited this wait(.2) ExpBar.Size = UDim2.new(0, 15, 0, (math.ceil(xp/(xps[level+1] * 100)) * 200)) -- edited elseif level.Value >= 30 then -- edited this wait(.2) ExpBar.Size = UDim2.new(0, 15, 0, 200) end end Player.Exp.Changed:connect(function() hudsize() end)
I believe this should work, what was happening was the local xp and the local level both had a .Value in them, it can't handle it. (unless it's been updated and it can) But this should work for you now.
wait(2) local xps = {0, 3, 6, 10, 15, 20, 25, 30, 40, 50, 65, 80, 95, 110, 125, 140, 155, 180, 210, 250, 300, 350, 400, 450, 500, 575, 650, 725, 825, 1000}; Player = game.Players.LocalPlayer function hudsize() repeat wait() until Player and Player.leaderstats local ExpBar = script.Parent.ExpBar local xp = Player.Exp.Value local level = Player.leaderstats.Level.Value local required = math.ceil(xp/xps[level] * 100) * 100 -- This should be Current EXP divided by needed exp times 100 if level < 30 then wait(.2) ExpBar.Size = UDim2.new(0, 15, 0, (required * 2)) elseif level >= 30 then wait(.2) ExpBar.Size = UDim2.new(0, 15, 0, 200) end end Player.Exp.Changed:connect(function() hudsize() end)