Humanoid.Died Sending a ton of remote events instantly

Hey everyone, i’m struggling a bit at the moment. I have a local script which is supposed to tell the server when that client has died. Then the server removes one from the list of players in a free for all.

My problem is that when the server recieves the remote event, it does not just subtract 1 from the number of duelers, but it subtracts a huge random amount. One time it was 19, another it was 7, etc… I really need to figure out how to make it only subtract once

The remote events are working fine, its just the server recieving it that’s getting all weird.

Here is the local script

local debounce

game.ReplicatedStorage.TrackDeath.OnClientEvent:Connect(function()
	debounce = true
	print("We are scanning for death")
	game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
		if debounce  then
			game.ReplicatedStorage.Died:FireServer(game.Players.LocalPlayer)
			print("Died")
			debounce = false
		end
	end)
end)

And here is the piece of the server script that picks it up

for count = 1, 300 do
	game.Workspace.SignPart.BillboardGui.Frame.Count.Text -= 1
			
	game.ReplicatedStorage.Died.OnServerEvent:Connect(function(player)
		duelers -= 1
		print("Duelers: ", duelers)
	end)
			
	if duelers == 1 then
		break
	end
	wait(1)
end

Please help if you can. Thanks.

Well the problem is because the server script is creating a new event listener for that remote event because it is inside a loop. So put that event out of the loop to fix the problem. You can also track when the player dies on the server.

2 Likes

Thanks man, this works :slight_smile:

Why don’t you just have the server track when they die instead of having the client fire a remote for it…?

I have a question though. The loop is told to break if it is equal to one, so why does it matter if its in the loop?

Because that creates more than one event listener for the same remote event. And when that remote event is fired, the events that are listening to it will be fired. Also, if you no longer need that event, you can disconnect it.