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

Problem with this levels script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Inside the player I have a IntValue called CraftingLevel and inside that a IntValue called CraftingEXP, inside that is this script (normal script), I wanted to be able to level them up like so, but it refuses to work:

EXP=script.Parent
Crafting=script.Parent.Parent
EXP.Changed:connect(function()
            if EXP.Value*10 == Crafting.Value and Crafting.Value<10 then
                EXP.Value = 0 
                Crafting.Value = Crafting.Value+1
    end
end)

Thanks

0
Well, the problem I'm seeing is that it's just a math error. EXP.Value * 10 == Crafting.Value. Maybe switch which side the * 10 is on and it should work. Tkdriverx 514 — 10y

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

Try

        if EXP.Value >= Crafting.Value * 10 then

instead.

If you don't want linear leveling (every level has the same number of steps between), try this:

        if EXP.Value >= Crafting.Value ^ 3 then

And here's a more efficient code (in case they gained a bunch of EXP where they gain more than one level:

local EXP = script.Parent
local Crafting = script.Parent.Parent

EXP.Changed:connect(function()
    while EXP.Value >= Crafting.Value * 10 do
        EXP.Value = EXP.Value - Crafting.Value * 10 -- Make sure this part is exactly the same as what is checked for in the conditional statement.
        Crafting.Value = math.min(Crafting.Value + 1, 10) -- Limits the level value to a maximum of 10
    end
end)

0
I'm afraid, it doesn't work. Mystdar 352 — 10y
0
What are the default values? Tkdriverx 514 — 10y
Ad

Answer this question