Im in need of help fixing my leveling system in my game

The script I have here is very simple and has way too many bugs. I’d like help help making this script more advanced and optimized to be better for the players and myself overall.

People leaving and joining the server caused many issues with the level system. The levels were stacking with other players and the effects for them were stacking too. I’m having many similar issues with scripts like this across my entire game with many other systems. It is a work in progress so any help and tips would be amazing.

I looked for solutions but I’m not 100% sure what to look up.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Thanks for any help and support!

Local Script in StarterCharacterScripts


4 Likes

Instead of storing all your levels inside different variables, you should instead use a single value to track player’ level. You should also create a seperate table for level requirements, like:

local Level = 0
local maxLevel = 25
local LvlReq = {[1]=60, [2]=300, [3]=600}

That way, you can create a much simpler level updater:

if TimeSpent.Value < LvlReq[Level] then Level -= 1 end —demote the player if they somehow level up twice
if Level == maxLevel then return end
if TimeSpent.Value >= LvlReq[Level+1] then
    if TimeSpent.Value < LvlReq[Level+2] then return end —Insures the player cannot level up to any level they do not meet the requirements of
    Level += 1
end
2 Likes