local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("KillsSaveSystem")
local ds2 = datastore:GetDataStore("CashSaveSystem")
local ds3 = datastore:GetDataStore("DeathSaveSystem")
local ds4 = datastore:GetDataStore("LevelSaveSystem")
local ds5 = datastore:GetDataStore("XPSaveSystem")


function onXPChanged(player, XP, level)
	if XP.Value>=level.Value * 10 then
		XP.Value = 0
		level.Value = level.Value + 1 
	end
end

function onLevelUp(player, XP, level)
	local m = Instance.new("Hint")
	m.Parent = game.Workspace
	m.Text = player.Name .. " has leveled up!"
	wait(3)
	m.Parent = nil
   player.Humanoid.Health = 0
end


function onPlayerRespawned(player)
	wait(5)

	player.Character.Humanoid.Health = player.Character.Humanoid.Health + player.leaderstats.Level * 10

	player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + player.leaderstats.Level * 10

end


function onPlayerEntered(newPlayer)

local stats = Instance.new(newPlayer)
  	stats.Name = "leaderstats"

local cash = Instance.new("IntValue",stats)
	cash.Name = "Cash" 	
	
local kills = Instance.new("IntValue",stats)
	kills.Name = "Kills"
	
local deaths = Instance.new("IntValue",stats)
	deaths.Name = "Deaths"

local level = Instance.new("IntValue",stats)
   level.Name = "Level"

local xp = Instance.new("IntValue",stats)
   xp.Name = "XP"

 kills.Value = ds1:GetAsync(newPlayer.UserId) or 0
 ds1:SetAsync(newPlayer.UserId, kills.Value)
 
 cash.Value = ds2:GetAsync(newPlayer.UserId) or 0
 ds2:SetAsync(newPlayer.UserId, cash.Value)

deaths.Value = ds3:GetAsync(newPlayer.UserId) or 0
 ds3:SetAsync(newPlayer.UserId, deaths.Value)

level.Value = ds4:GetAsync(newPlayer.UserId) or 0
 ds4:SetAsync(newPlayer.UserId, level.Value)

xp.Value = ds5:GetAsync(newPlayer.UserId) or 0
 ds5:SetAsync(newPlayer.UserId, xp.Value)
   
   cash.Parent = stats
	stats.Parent = newPlayer
	kills.Parent = stats
	deaths.Parent = stats
   level.Parent = stats
   xp.Parent = stats
---updater
	xp.Changed:connect(function() onXPChanged(newPlayer, xp, level) end)
	level.Changed:connect(function() onLevelUp(newPlayer, xp, level) end)
	
 		kills.Changed:connect(function()
  	 ds1:SetAsync(newPlayer.UserId, kills.Value)
 	 end)
 
 	  	cash.Changed:connect(function()
  	 ds2:SetAsync(newPlayer.UserId, cash.Value)
 	 end)

 	 	deaths.Changed:connect(function()
     ds3:SetAsync(newPlayer.UserId, deaths.Value)
	 end)
		
 		level.Changed:connect(function()
  	ds4:SetAsync(newPlayer.UserId, level.Value)
 	end)
 		xp.Changed:connect(function()
  	ds5:SetAsync(newPlayer.UserId, xp.Value)
	end)

1 comment

0

Can you please not ask us to modify scripts which you did not write