Good leveling system?

So I am making a big update for this game
https://www.roblox.com/games/refer?SortName=MyFavorite&PlaceId=3656132490&Position=1&PageType=Home&LocalTimestamp={localTimestamp}&TotalInSort=6&SortPosition=2&PageId=0cefc162-4132-4778-9248-f7f3eb5edba3
And I am making a leveling system. I will put my code here and see how I can improve it. Levels will currently just give you access to new areas.

function gainXP(plr)
	local lvls = plr.Levels
	
	local xpNeeded = lvls.XP_REQUIREMENT.Value -- 1250
	local lvl = lvls.Level
	local xp = lvls.XP
	local xpToAdd = lvls.XP_ADD.Value -- 250 currently but will be changed to 5 later
	
	if xpNeeded ~= nil then
	
	print(xpNeeded)
	print(xpToAdd)
	
	while wait(5) do
		
		xp.Value = xp.Value + xpToAdd
		print("XP Success")
		
		if xp.Value >= xpNeeded then
			lvl.Value = lvl.Value + 1
			xp.Value = 0
			
			xpToAdd = xpToAdd + math.sqrt(math.random(7, 17) * math.random(2, 2.65))
			xpToAdd = math.floor(xpToAdd)
			print(xpToAdd)
			print("Success")
			
			xpNeeded = xpNeeded * math.sqrt(math.ceil(math.pow(1.5, math.random(7, 10))) * (math.random(1, 1.5)) ) --do some multiplying
			local divided = xpNeeded / math.random(15, 25)
			local rounded = 5 * math.floor(divided)
			xpNeeded = rounded
			
			print(xpNeeded)
			print("Success")
		end
	end
	end
end

I want to make it not really easy to level up but not too hard, so people will have to stay on longer (or collect cocoa since that will give you xp) if they want to level up to get to a new area, but they won’t have to stay on for a very long time.

I tested it a few times and found out the xp requirement would go up by 500-1000, and the xp to add would go up by 2-6 (might not be accurate because this was only tested twice). Is this ok for what I just said?

  • Great leveling system
  • Bad leveling system
  • It is ok
  • Needs to be redone - reply how I could!

0 voters

  • It should not change at all
  • How much the xp requirement and the xp to add goes up should go down
  • How much the xp requirement goes up should go down
  • How much the xp to add goes up should go up
  • Other - write in a reply!

0 voters

For the second poll it would be very nice when you pick do this:

  • If you picked “How much the xp requirement and the xp to add goes up should go down” reply what would be better
  • If you picked “How much the xp requirement goes up should go down” reply what would be better
  • If you picked “How much the xp to add goes up should go up” reply what would be better
1 Like

Your loop will run infinitely, even after the player leaves. Don’'t use abbreviations like “plr” or “lvl”, just write the word out, “player”, or “level”. Fix your indentation. xpNeeded can never be nil.

Don’t make XP requirement increases random.

4 Likes

Ok then I’ll make exp requirement scale with the levels!

Using a while wait(5) do is a bad practice in this circumstance, you should use changed event:
Instead of:

You can write:

xp.Changed:Connect(function()
    --Code
end)

Thanks for reading

1 Like

I think that the function might not ever fire though… Correct me if I’m wrong.

1 Like

That function will be fired when xp (value, name, parent, etc) has changed

1 Like