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

Why does my level up script not change my leaderstats, and only change my Gui?

Asked by 4 years ago
Edited 4 years ago

What I'm trying to do is make it so when your xp is over your xp required to level up, you level up. The xp is reset to 0 after leveling up, and the xp required to level up again is also increased, however it is not increasing my level by 1.

wait(3)
xp = script:findFirstAncestor("PlayerGui").Parent.leaderstats.Exp.Value
xpn = script:findFirstAncestor("PlayerGui").Parent.leaderstats.ExpNeeded.Value
level = script:findFirstAncestor("PlayerGui").Parent.leaderstats.Level.Value

while wait()do
script.Parent.Text = xp .. "/" .. xpn 
if xp >= xpn then
    level = level + 1
    xpn = xpn * 1.25
    xp = 0
end
end

-- This makes you level up, and your experience needed to level again is increased. --
0
i just edited it into code blocks Acratixx 9 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Those variables at the top are just storing the values of the Exp, ExpNeeded and Level. If you change the variable, you're not actually changing the value of the objects.

Drop the .Value on the variables at the top so you're referencing the objects themselves, then change the value in the loop using the .Value.

Here's what it would look like

wait(3)
xp = script:findFirstAncestor("PlayerGui").Parent.leaderstats.Exp
xpn = script:findFirstAncestor("PlayerGui").Parent.leaderstats.ExpNeeded
level = script:findFirstAncestor("PlayerGui").Parent.leaderstats.Level

while wait()do
script.Parent.Text = xp.Value .. "/" .. xpn.Value 
if xp.Value >= xpn.Value then
    level.Value = level.Value + 1
    xpn.Value = xpn.Value * 1.25
    xp.Value = 0
end
end
0
Thank you! Acratixx 9 — 4y
Ad

Answer this question