I made Kills leaderstats for whenever you kill a player and/or a bot, and it works perfectly fine until someone else joins the server. If another person joins the server, it completely pauses your kills leaderstats and only the other person can earn kills.
Here is the game: https://www.roblox.com/games/4708400827/Sword-fighting-AI-Testing-v2 I have made it 5 player servers so you can test it out with other people for yourself.
Here is my leaderboard script:
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)
game.Workspace:WaitForChild("Bot1").Bot.Humanoid.Died:Connect(function()
local BotHumanoid1 = game.Workspace:WaitForChild("Bot1").Bot.Humanoid
for i, Child in pairs(BotHumanoid1:GetChildren()) do
if Child:IsA('ObjectValue') and Child.Value 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)
game.Workspace:WaitForChild("Bot2").Bot.Humanoid.Died:Connect(function()
local BotHumanoid2 = game.Workspace:WaitForChild("Bot2").Bot.Humanoid
for i, Child in pairs(BotHumanoid2:GetChildren()) do
if Child:IsA('ObjectValue') and Child.Value 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)
Thank you!
