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

Why is the xp bar becoming 1/4 (gui) of the required amout of xp?

Asked by 5 years ago
Edited 5 years ago

Edit: I printed FR and it prints 0.125 everytime the xp is half the required amount.

local user = game.Players.LocalPlayer
local stats = user:findFirstChild("DataFolder")
lvl = stats:findFirstChild("level")
xp = stats:WaitForChild("level"):WaitForChild("xp")
xprequire = stats:WaitForChild("level"):WaitForChild("XpRequire")
local amount = xprequire

print(xprequire.Value)
wait(1)

local function changed() -- This is the bar btw
    local FR = (xp.Value / (lvl.Value * amount.Value))
    script.Parent.Size = UDim2.new(FR, 0, 0, 50)
end

xp.Changed:connect(changed)
xprequire.Changed:connect(changed)
lvl.Changed:connect(changed)

while true do
    wait()
    script.Parent.Parent.Text = xp.Value.. "/ " ..amount.Value
    script.Parent.Parent.Parent.LevelShow.Text = "Level " ..lvl.Value

    if xp.Value >= amount.Value then
        lvl.Value = lvl.Value + 1
        wait()
        xp.Value = 0
        amount.Value = amount.Value * 2
    end
    if amount.Value == 0 then
        amount.Value = 100
    end
end

while true do
    wait()
    script.Parent.Parent.Parent.LevelShow.Text = "Level " ..lvl.Value
end
0
Add a print after line 12 'print(FR)' and make sure the variable FR is the actual size you want the XP bar to become. YabaDabaD0O 505 — 5y
0
I printed FR and it prints 0.125 everytime the xp is half the required amount SamthekidRSsl 58 — 5y
0
and the size of the outer bar is {0, 235},{0, 50} SamthekidRSsl 58 — 5y
0
And where the bar "function" is it uses events rather than a loop for this type of thing. SamthekidRSsl 58 — 5y
View all comments (2 more)
0
You should never use a loop to check if a property changes. Bad practice. User#19524 175 — 5y
0
Its fine now i got it all figured out i just rewrote it but more simple SamthekidRSsl 58 — 5y

Answer this question