I have this script here, how could i make it so that lets say every 1000 xp you get a level and it saves your level. and I can easily shpw it on a gui?
local Auto_Load = true
local Auto_Save = true
local Save_On_Leave = true
local Stats = {"XP","SkinIndex","Wins","Kills"}
local StatsNotToSave = {}
game.Players.PlayerAdded:connect(function(p)
wait()
local ODS = game:GetService("DataStoreService"):GetDataStore(p.userId)
for i = 1,#Stats do
ODS:UpdateAsync(Stats[i], function(old)
if Stats[i] == "SkinIndex" then
return old or 1
else
return old or 0
end
end)
end
local l = Instance.new("Model", p)
l.Name = "stats"
for i = 1,#StatsNotToSave do
S = Instance.new("NumberValue", l)
S.Name = StatsNotToSave[i]
end
for i = 1,#Stats do
S = Instance.new("NumberValue", l)
S.Name = Stats[i]
if Auto_Load then
S.Value = ODS:GetAsync(Stats[i])
end
if Auto_Save then
S.Changed:connect(function()
ODS:SetAsync(Stats[i], S.Value)
end)
end
end
end)
if Save_On_Leave then
game.Players.PlayerRemoving:connect(function(p)
local ODS = game:GetService("DataStoreService"):GetDataStore(p.userId)
for i = 1,#Stats do
stat = p.stats:FindFirstChild(Stats[i])
if stat then
ODS:UpdateAsync(stat.Name, function(old)
return stat.Value
end)
end
end
end)
end```