Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When the humanoid dies, it returns a message 4 times even though the humanoid died once?

So I was creating a killfeed that involved a RemoteEvent, ServerScript and a LocalScript.

Everything was working fine, but the killfeed template was cloned 4 times... Isn't the Humanoid.Died function supposed to fire once?

Here's the ServerScript inside the ServerScriptService:

game.ReplicatedStorage.TakeDamage.OnServerEvent:Connect(function(player,damage,hum)
	if hum then
		hum:TakeDamage(damage)
		hum.Died:Connect(function()
			local cooldown = true
			if cooldown == true then
				cooldown = false
				print('killed')
			game.ReplicatedStorage.AddKill:FireAllClients(player.Name,hum.Parent.Name)
			end
		end)
	end
end)

Here's the LocalScript inside the ScreenGui:

game.ReplicatedStorage.AddKill.OnClientEvent:Connect(function(killerName,victimName)
	local killfeedLabel = script.Parent.KillfeedTemplate:Clone()
	killfeedLabel.Parent = script.Parent
	killfeedLabel.Text = "<"..string.upper(killerName).."> KILLED <"..string.upper(victimName)..">"
	killfeedLabel.Visible = true
	wait(3)
	game:GetService("TweenService"):Create(killfeedLabel,TweenInfo.new(0.5),{TextTransparency = 1,TextStrokeTransparency = 1}):Play()
	wait(0.5)
	killfeedLabel:Destroy()
end)

Sorry if it's hard to read...

I tried to find any article I could find, but I did not find any helpful. Any sort of help is appreciated!

1 answer

✓ Accepted answer

You are connecting the Died event in the OnServerEvent. Meaning everything you fire that event you are connecting even more Died events. So when the humanoid does die, that function is being called that many times.

4 comments

0

Also why would take damage be a RemoteEvent, Are clients incharge of doing damage? An exploiter can simply fire that event and do all the damage they want.

0

Well, how can I prevent an exploiter from firing the event? I'm new to combating exploiters...

0

Why are you doing damage through a remote event?

0

Well, It's a multiplayer game, so I need the damage to be done on the server side. That's why I'm using a remote event.

This discussion is preserved as it was. New answers, comments, and votes are closed.