[REPOST]
I am making a swordfighting game which has AI that can also fight. I have made leaderstats for Deaths, and also Kills (player to player kills). But I would also like to make it so it adds one kill to the leaderboard when you kill a bot (player to bot kills).
This is my code currently (mostly from tutorials + free models):
local Players = game.Players
local Template = Instance.new 'BoolValue'
Template.Name = 'leaderstats'
Instance.new('IntValue', Template).Name = "Kills"
Instance.new('IntValue', Template).Name = "Deaths"
Players.PlayerAdded:connect(function(Player)
wait(1)
local Stats = Template:Clone()
Stats.Parent = Player
local Deaths = Stats.Deaths
Player.CharacterAdded:connect(function(Character)
Deaths.Value = Deaths.Value + 1
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)
Thank you!

2 comments
So, what exactly is your problem?
I'm trying to detect the death of a bot by a player so it can add a kill to a leaderboard.