I need to make another leaderboard but it breaks every time help please

Hello everybody! So i have a script in ServerScriptService that basically saves kills with a datastore in the leaderboard, However i want to make another leaderboard that gives you cash when you kill somebody with no save or datastore but it seems i can’t do it and everytime i try scripting it it breaks the original kill leaderboard script in ServerScriptService, So i wonder if somebody can be generous and give me a script for when you kill somebody and get cash in the leaderboard but it doesn’t save or help me at scripting it, And here is the saving kill leaderboard in the serverscriptservice:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MoneyStats") 

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	
	local Kills= Instance.new("IntValue", Leaderstats)
	Kills.Name = "Kills" 
	Kills.Value = 0

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Kills.Value = Data.Kills 
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		
		["Kills"] = Player.leaderstats.Kills.Value; 
	})
end)
local Players = game.Players

local Template = Instance.new 'BoolValue'
Players.PlayerAdded:connect(function(Player)
	local Stats = Template:Clone()
	Stats.Parent = Player
	Player.CharacterAdded:connect(function(Character)
		local Humanoid = Character:FindFirstChild "Humanoid"
		if Humanoid then
			Humanoid.Died:connect(function()
				for i, Child in pairs(Humanoid:GetChildren()) do
					if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
						local Killer = Child.Value
						if Killer:FindFirstChild 'leaderstats' and Killer.leaderstats:FindFirstChild "Kills" then
							local Kills = Killer.leaderstats.Kills
							Kills.Value = Kills.Value + 1
						end
						return 
					end
				end
			end)
		end
	end)
end)

  1. What do you want to achieve?
    I want to make another leaderboard that gives your cash in the leaderboard whenever you kill a player with no datastore or save and doesn’t break the kill script in Serverscriptservice.

  2. What is the issue?
    Every time i try scripting it it breaks the Original script in serverscriptservice By either showing only the cash leaderboard or breaks the kill script in serverscriptservice and doesn’t work.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried scripting the script but didn’t work and i also did look for solutions on the developer hub but didn’t find any.

1 Like

Just add another value like for example

Local kill = instance.new copy that pet all the way to kills.value = 0 just rename it the designated leaderstat

You can then add as many as you want and put the custom script. However for me I’d id like cash you need to put

Local cash = cash.value = 0

1 Like
local amount_to_give = 25

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MoneyStats") 

game:GetService('Players').PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"

	local Kills = Instance.new("IntValue", Leaderstats)
	Kills.Name = "Kills" 
	Kills.Value = 0

	local Cash = Instance.new("IntValue", Leaderstats)
	Cash.Name = "Cash" 
	Cash.Value = 0

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Kills.Value = Data.Kills 
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {

		["Kills"] = Player.leaderstats.Kills.Value; 
	})
end)

local Players = game:GetService('Players')
local Template = Instance.new('BoolValue')

Players.PlayerAdded:Connect(function(Player)
	local Stats = Template:Clone()
	Stats.Parent = Player
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:FindFirstChild('Humanoid', false)
		if (Humanoid) then Humanoid.Died:Connect(function()
				for _, Child in pairs(Humanoid:GetChildren()) do
					if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
						local Killer = Child.Value
						if Killer:FindFirstChild('leaderstats') and Killer.leaderstats:FindFirstChild("Kills") then
							local Kills, csh = Killer.leaderstats.Kills, Killer.leaderstats.Cash
							Kills.Value += 1
							csh.Value += amount_to_give
						end
						return;
					end
				end
			end)
		end
	end)
end)
2 Likes

Thank you very much! Now i can complete my game.

1 Like