How to stop an event from firing way to many times

	for i,v in pairs(game.Players:GetPlayers()) do
		v.Character:FindFirstChild("Humanoid").Died:Connect(function() 
			if v:FindFirstChild("IsContestant") then
				print("OMG")
				return
			end
			return
	end
	wait()
end

Ok so problem is when a huamoid dies it prints tthe omg think 200 to 300 times upcourse its not a problem now but in my game I want it to subtract points when u die and if this continues random numbers will be subtracted so yah, any suggestions?

Have you tried to use flags as bool value?
Example:

local flag = false

	for i,v in pairs(game.Players:GetPlayers()) do
		v.Character:FindFirstChild("Humanoid").Died:Connect(function() 
			if v:FindFirstChild("IsContestant") and flag == false then
        flag = true
				print("OMG")
         flag = false
				return
			end
			return
	end
	wait()
end

Hmm good sugestion i will try i never knew what flags were lol

Do i have to put this in a while loop

Are you by any chance calling this loop multiple times? Because connecting it once should make it only fire once. If you want to connect a Died event to a player you could do this instead.

function PlrAdded(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid",5).Died:Connect(function()
			if plr:FindFirstChild("IsContestant") then
				print("OMG")
			end
		end)
	end)
end

game.Players.PlayerAdded:Connect(PlrAdded)
for _,plr in pairs(game.Players:GetPlayers()) do
	coroutine.resume(coroutine.create(function() PlrAdded(plr) end))
end

I want to call it multip,e times this is for a deathmatch game

Test what I did so you can understand it. It fires every time a character dies.

hmm why player added doesnt playeradded only run when a player joins

yes, this should not be called more than once. It should be at the beginning of the script.

yah but I want the script to run if any player dies and has that value inside them not just if thyre new players

also its not working for some reason

Updated it so it takes into account players already in a game, but I don’t think you understand how PlayerAdded is supposed to be used. It should be running from the beginning of when the server starts. This will make it so that all players in the game are connected to it forever.

oof idk why its working would the flag method the other person suggested work? or should I put it ina while true do loop

no no no. Putting it in a while true do loop is the problem you have from the start. You seem to be calling/connecting the Died event multiple timed on the same character. This is what is causing it to print OMG again and again.

You can try doing what the other person says even though it isn’t a good method it might solve your problem and make the code work. Your event will still fire hundreds of times for no reason though.

Oh I thought returns would stop it from doing that

Nope. As you seem to be initiating/connecting the event multiple times, it would fire the function for every time you connected the event to the character.

Try copy and pasting what I have above again. It should work unless the IsContestant doesn’t exist or you are not placing it in the right part of the script.

This one?
function PlrAdded(plr)
plr.CharacterAdded:Connect(function(char)
char:WaitForChild(“Humanoid”).Died:Connect(function()
if plr:FindFirstChild(“IsContestant”) then
print(“OMG”)
end
end)
end)
end

game.Players.PlayerAdded:Connect(PlrAdded)
for _,plr in pairs(game.Players:GetPlayers()) do
coroutine.resume(coroutine.create(function() PlrAdded(plr) end))
end

Yes that is the one. It should do what you wanted if it is being used correctly.