I have a Leveling System, but I can't skip over levels. How do I change it so I can do that?
Currently, the leveling system that I have works. Although I'm not entirely for sure how I would change it to make it a little bit more random instead of leveling up every 700 xp (which is also a problem I need solved, if possible.), I would like to know what I should add so then I can skip levels.
For example, if I put into my values 1400 and my current XP is 0, it tells me that my level is 2, but instead it should be 3. Here is the code:
01 | local level = game:GetService( "DataStoreService" ):GetDataStore( "DiscWarsLevels" ) |
02 | local xp = game:GetService( "DataStoreService" ):GetDataStore( "DiscWarsXP" ) |
03 | local axp = game:GetService( "DataStoreService" ):GetDataStore( "DiscWarsAmountXP" ) |
05 | function savedata(dataname, playerid, value) |
06 | game:GetService( "DataStoreService" ):GetDataStore(dataname):SetAsync(playerid, value) |
09 | game.Players.PlayerAdded:connect( function (player) |
11 | local leader = Instance.new( "Folder" ) |
12 | leader.Name = "leaderstats" |
13 | leader.Parent = player |
15 | local levels = Instance.new( "IntValue" ) |
16 | levels.Value = level:GetAsync( tostring (player.userId)) or 1 |
18 | levels.Parent = player:WaitForChild( "leaderstats" ) |
20 | local xps = Instance.new( "NumberValue" ) |
21 | xps.Value = xp:GetAsync( tostring (player.userId)) |
25 | local xpn = Instance.new( "IntValue" ) |
26 | xpn.Value = axp:GetAsync( tostring (player.userId)) or 700 |
30 | xps.Changed:connect( function () |
31 | if player:WaitForChild( "XP" ).Value > = player:WaitForChild( "XPNeeded" ).Value then |
32 | levels.Value = levels.Value + 1 |
33 | xpn.Value = xpn.Value + 700 |
34 | savedata( "DiscWarsLevels" , player.userId, levels.Value) |
35 | savedata( "DiscWarsXP" , player.userId, xps.Value) |
36 | savedata( "DiscWarsAmountXP" , player.userId, xpn.Value) |
38 | savedata( "DiscWarsLevels" , player.userId, levels.Value) |
39 | savedata( "DiscWarsXP" , player.userId, xps.Value) |
40 | savedata( "DiscWarsAmountXP" , player.userId, xpn.Value) |
42 | savedata( "DiscWarsLevels" , player.userId, levels.Value) |
43 | savedata( "DiscWarsXP" , player.userId, xps.Value) |
44 | savedata( "DiscWarsAmountXP" , player.userId, xpn.Value) |
48 | game.Players.PlayerRemoving:connect( function (player) |
49 | savedata( "DiscWarsLevels" , player.userId, player.leaderstats.Value) |
50 | savedata( "DiscWarsXP" , player.userId, player.XP.Value) |
51 | savedata( "DiscWarsAmountXP" , player.userId, player.XPNeeded.Value) |