01 | game.Players.PlayerAdded:connect( function (Player) ----- When a Player joins a server this function happens |
02 | local Data = Instance.new( "IntValue" ,Player) ----Makes an IntValue inside Player |
03 | Data.Name = "Data" -----It's name is Data ([Note]: You could change it to leaderstats if you would like a leaderboard with it.) |
04 | local XP = Instance.new( "IntValue" ,Data) ----Makes a IntValue inside Data |
05 | XP.Name = "XP" |
06 | XP.Value = 0 |
07 | local Level = Instance.new( "IntValue" ,Data) ------- Makes an IntValue Inside Data |
08 | Level.Name = "Level" ------- It's name is Level |
09 | Level.Value = 1 |
10 | XP.Changed:connect( function () XPChange(Player,XP,Level) end ) ---- To change the XP, XPChanged function occours |
11 |
12 | end ) |
13 |
14 | function XPChange(Player,XP,Level) ------ XPChanged function |
15 | if XP.Value > = Level.Value* 150 then ----- this function occours happens if the Level's Value is greater or equal to this 150 ([Note]: Change 150 to the max XP) |
16 | XP.Value = 0 --- Resets the XP |
17 | Level.Value = Level.Value+ 1 |
18 | end |
19 | end |
By just making it a global script. There is no reason why it should be local.