Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Problem with this levels script?

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

1 comment

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.

1 answer

✓ Accepted answer

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)

2 comments

0

I'm afraid, it doesn't work.

0

What are the default values?

This discussion is preserved as it was. New answers, comments, and votes are closed.