Issue With the Leaderboard When Killing a Zombie

Hello, I am trying to create a basic zombie game and I am having trouble with adding a kills leaderboard. I believe the main issue is the script detecting a zombie as a player. How would I fix this?

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local kills = Instance.new("NumberValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("NumberValue", leaderstats)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		
		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
	
			local zombie1 = game.ReplicatedStorage.Zombie
			local killer = zombie1.Value
			if zombie1 and killer then
				killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			end
		end)
	end)
end)
local players = game:GetService("Players")
local storage = game:GetService("ReplicatedStorage")

players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"

	local kills = Instance.new("NumberValue")
	kills.Parent = leaderstats
	kills.Name = "Kills"
	kills.Value = 0

	local deaths = Instance.new("NumberValue")
	deaths.Parent = leaderstats
	deaths.Name = "Deaths"
	deaths.Value = 0

	player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")

		humanoid.Died:Connect(function(died)
			deaths.Value += 1

			local zombie1 = storage:WaitForChild("Zombie")
			local killer = zombie1.Value
			if zombie1 and killer then
				killer.leaderstats.Kills.Value += 1
			end
		end)
	end)
end)

Can I see how you’re tagging the killer? This script looks fine.

What do you mean by that? The killer is supposed to be the player.

I understand but how are you determining the killer? I assume there’s a second unshared script?

The other scripts came with the free model of the zombie, nothing else.

local zombie1 = storage:WaitForChild("Zombie")
local killer = zombie1.Value

zombie1 I presume is a StringValue/ObjectValue instance which references the player which killed the zombie?

yeah it’s just a placeholder for it

It’s the identifier which determines who the killer is, is it a StringValue or ObjectValue instance?

humanoid.Died:Connect(function(died)
			deaths.Value += 1

			local zombie1 = storage:WaitForChild("Zombie")
			local killer = zombie1.Value
			if zombie1 and killer then
				killer.leaderstats.Kills.Value += 1
			end
		end)

This is only detecting if your own character’s “Humanoid” instance has died by the way.
Since “humanoid” is defined as "character:WaitForChild(“Humanoid”). Which is the characters “Humanoid” instance not the zombies “Humanoid” instance.

Oh okay it makes sense now, thanks!

No problem, here’s a few useful resources regarding leaderboards:

https://education.roblox.com/en-us/resources/adventure-game-creating-a-leaderboard