Anti-God PVP - PlayerDeath Overflowing When Called

Hello everyone,

I am attempting to create and Anti-God PVP Lua script. Basically, if a player who is in god mode kills another player who is not in god mode, the script will kill the attacker. However, when I test it by being in god mode and killing a player, it seems to loop until it crashes, and I have no idea why. Here is my code.



hook.Add( "PlayerDeath", "PlayerDeath.checkgod", function(victim, inflictor, attacker)
	print("POINT1")
	if attacker:IsPlayer() then
		print("POINT2")
		if attacker:HasGodMode() then
			print("POINT3")
			attacker:Kill()
		end
	end
end)


The prints are means of debugging. When I kill in god mode, the console goes insane and loops POINT1 POINT2 POINT3 POINT1 POINT2 POINT3 until it eventually crashes.

Based on a few hours of research, it all seems to be correct. Am I missing something stupid, or will this simply not work?
Any help would be greatly appreciated.

Thanks

Adam

You are using the wrong type of hook, use a damage hook instead.

Not to toot my own horn or anything but: http://steamcommunity.com/sharedfiles/filedetails/?id=440157563

What you are looking for is hook.Add(“EntityTakeDamage”, [NAME], [FUNCTION]) http://wiki.garrysmod.com/page/GM/EntityTakeDamage

Thank you both so much! That worked like a charm. Thank you for the recommendation on the addon, Artik, but I am looking for more room for customization. What a small world, Artik, I remember the days on Aycerus. My steam name is Science.

Anyways, thank you both very much,

Adam