Leveling up more than 1 (SOLVED)

I have a leveling up system that should level up a player if they have more than LevelPoints(Exp) than the required level points to level up

Problem is, If player earned more than the required level points, They will level up by 2 or 3, Like if your Required Level Point is 120 and you earned 120+ levelpoints(Exp), You level up more than1.

	levelpoint.Changed:Connect(function(c)
		if levelpoint.Value >= required.Value then
			levelpoint.Value = 0

			addpoint.Value += 3

			level.Value += 1
			required.Value = level.Value * 100 
			p:LoadCharacter()
		end
	end)
1 Like

Would this work I haven’t checked it yet.

levelpoint.Changed:Connect(function(c)
		if levelpoint.Value >= required.Value then
            local oldlevel = levelpoint.Value

			levelpoint.Value = 0
			addpoint.Value += 3

			level.Value += 1
			required.Value = level.Value * 100
            if oldlevel >= required.Value then
               levelpoint.Value = 0
			   addpoint.Value += 3

			   level.Value += 1
			   p:LoadCharacter()
            else
               p:LoadCharacter()
            end
		end
	end)

while this is not what you asked for this is another method of calculating player levels with a single value

-- Script
local IncrementExperience = function(player, amount)
	player.Experience.Value += amount
end
-- LocalScript
local difficulty = 5

local GetLevel = function(experience)
	return math.floor(math.sqrt(experience) / difficulty)
end

local GetExperience = function(level)
	return level ^ 2 * difficulty ^ 2
end

game.Players.LocalPlayer.Experience.Changed:Connect(function(value)
	local level = GetLevel(value)
	local nextLevelExperience = GetExperience(level + 1)
	local remainingExperience = nextLevelExperience - value
	print("Level:", level)
	print("Experience Remaining:", remainingExperience)
end)

You could just set their exp value to zero once they level up.

Thats what I did:

levelpoint.Value = 0

Same problem, If you have 120 levelpointrequired and earned 121 or more levelpoints, It will level you up 2 or 3 times

Add a debounce to it and see if that fixes it.

1 Like

if you created all the variables in Player class with folder and datastore, you can handle level in another script. So, you are getting exp, you are getting requiredexp, you are creating serverscript, and in it coding algorithm:

function LevelUp()
   Exp -= RequiredExp
   Level += 1
   RequiredExp = Level * 100
end

Exp.Changed:Connect(function()
    if Exp >= RequiredExp then
        LevelUp()
     end
end)

Try to write code like what was above