Xp level system

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```
1 Like

make a condition in a script which asks: if player.leaderstats.xp.value == "1000" then player.leaderstats.level.value = player.leaderstats.level.value + 1

local DSS = game:GetService("DataStoreService")
local Data = DSS:GetDataStore("Data")

game.Players.PlayerAdded:Connect(function(plr)
	
	local loadedData = Data:GetAsync(plr.UserId)
	
	local stat = Instance.new("Folder",plr)
	stat.Name = "leaderstats"
	
	local xp = Instance.new("IntValue",stat)
	xp.Name = "XP"
	xp.Value = 0
	
	local lvl = Instance.new("IntValue",stat)
	lvl.Name = "Level"
	lvl.Value = 1
	
	if loadedData then
		xp.Value = loadedData["XP"].Value
		lvl.Value = loadedData["Level"].Value
	end
	
	xp.Changed:Connect(function()
		if xp.Value >= 1000 then
			lvl.Value += 1
			xp.Value -= 1000
		end
	end)	
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Data:SetAsync(plr.UserId,{["XP"] = plr.leaderstats.XP.Value,["Level"] = plr.leaderstats.Level.Value})
end)

not sure if that kind of datastoring works though…

How would I intergrate that into the current script I have??

im too lazy to start editing that bruh

grind never stops
and im not your BRA

When a player gets a level, perhaps you can try triggering a RemoteEvent to FireClient that player. Then, use LocalScript on that TextLabel/etc to do TweenPosition/Visible.