Custom wins/death handler issue (perhaps a delay?)

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)

Im not sure if this will work, but try to add a wait(1) function here:

if Killer then
wait(1) -- HERE
local Check_Killer = Killer.Character:FindFirstChild("Humanoid")
if Check_Killer.Health <= 0 then
return
end

Dont mind the one on the top, I meant here:

if Tag then
wait(1)
local Killer = Players:FindFirstChild(Tag.Value)
if Killer then
local Check_Killer = Killer.Character:FindFirstChild("Humanoid")
if Check_Killer.Health <= 0 then
     return
end

That doesn’t change anything though… I commented out the wait(1) because sometimes it would fire anyways. Adding a wait(1.5) maybe?

No, try to make it 0.2 seconds, because in a second the player would probably be respawned already.

Less wait time = Increased chance to happen

In this part, add a print(Check_Killer.Health).

local Check_Killer = Killer.Character:FindFirstChild(“Humanoid”)
print(Check_Killer.Health)
if Check_Killer.Health <= 0 then
return
end

then tell me the output

If there is lag and they tie, the other player might not fire the event before a sec or so later sometimes so

The client does not fire the event, the server fires the event to the client.

uncomment the wait(1) that you commented, and add the print() function, and tell me the output.

That would just print though. Would it not?

Yea… Tell me what does the print() return when the glitch happens…

Add the print function like this ^^^

Sure, in a second… Keep typing to send this. Lol

Prints 0 twice so far. No idea what’s the issue still though. But I’ll try more

I think that print fixed the issue actually, weirdly…

Its probably because of somehow health not updating, with print() its updating the health value in the script.

But I’m curious, might there be a lag issue regarding this in some cases without wait?

Probably, if I was you, I would keep the wait, and probably reduce it to like 0.5 seconds.

Ok, I will. Thank you for this though. ^.^