Hello!
I’m having an issue with my leaderboard system in my Roblox game. The leaderboard correctly displays kills and deaths, but there’s a strange bug when it comes to counting kills. When I kill a player for the first time, the kill count remains at 0. It only updates to 1 after I kill a second player. However, the death count works perfectly and updates immediately.
Also there are nothing errors in the console.
I’ve shared my code below for reference. I would appreciate any help or insights into why the kills are not being counted correctly on the first kill. Thank you for help!
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)