When two players tie with each other, the RemoteEvents gets fired sometimes, so I assume there’s a delay going on in here… I might be wrong, but I’m 100% confused about this.
local Players = game:GetService("Players")
local Event = game:GetService("ReplicatedStorage"):FindFirstChild("Events"):FindFirstChild("PLAYER_KILLED_PLAYER")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if Humanoid then
local h = Instance.new("StringValue")
h.Name = "creator"
h.Parent = Humanoid
Humanoid.Died:Connect(function()
--wait(1)
local Stats = Player:FindFirstChild("leaderstats")
if Stats then
local Reset_Killstreak = Stats:FindFirstChild("Killstreak")
if Reset_Killstreak then
Reset_Killstreak.Value = 0
local Folder = game:GetService("ServerScriptService"):FindFirstChild("DataStore")
local Deaths = Folder[Player.Name]:FindFirstChild("Total Deaths")
if Deaths then
Deaths.Value = Deaths.Value + 1
local Tag = Humanoid:FindFirstChild("creator")
if Tag then
local Killer = Players:FindFirstChild(Tag.Value)
if Killer then
local Check_Killer = Killer.Character:FindFirstChild("Humanoid")
if Check_Killer.Health <= 0 then
return
end
Event:FireClient(Player, Killer.Name, Killer.TeamColor, "DEFEATED")
Event:FireClient(Killer, Player.Name, Player.TeamColor, "KILLED")
local Killer_Stats = Killer:FindFirstChild("leaderstats")
if Killer_Stats then
local Killer_Wins = Killer_Stats:FindFirstChild("Wins")
if Killer_Wins then
Killer_Wins.Value = Killer_Wins.Value + 1
local Wins = Folder[Tag.Value]:FindFirstChild("Total Wins")
if Wins then
Wins.Value = Wins.Value + 1
local Killstreak = Killer_Stats:FindFirstChild("Killstreak")
if Killstreak then
Killstreak.Value = Killstreak.Value + 1
local Killstreak_Folder = Folder[Tag.Value]:FindFirstChild("Best Killstreak")
if Killstreak_Folder then
if Killstreak.Value > Killstreak_Folder.Value then
Killstreak_Folder.Value = Killstreak.Value
end
end
end
end
end
end
end
end
end
end
end
end)
end
end)
end)
Remote event
local StarterGui = game:GetService("StarterGui")
local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("PLAYER_KILLED_PLAYER")
Event.OnClientEvent:Connect(function(name, color, check)
if check == "KILLED" then
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "[Server] You won against " .. name;
Color = color.Color;
Font = Enum.Font.SourceSansBold;
FontSize = Enum.FontSize.Size24;
})
elseif check == "DEFEATED" then
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "[Server] You lost against " .. name;
Color = color.Color;
Font = Enum.Font.SourceSansBold;
FontSize = Enum.FontSize.Size24;
})
else
local Player = game:GetService("Players").LocalPlayer
Player:ClearAllChildren()
Player:Kick()
end
end)