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
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
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.
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.
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