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)
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.