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

Why does this anti team kill script not work?

I got this from the scripting helpers forum. I am trying to get it so that when someone of one team trys to shoot another person of the same team, nothing will happen(Meaning that the other person will not take damage). Why does it not work? The script is:

`thingy.Touched:connect(function(hit)
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.TeamColor == game.Players.LocalPlayer.TeamColor then
return false
else
player.Character.Humanoid:TakeDamage(5)
end)
`

3 answers

✓ Accepted answer

You never check to see if the thing that touches it is a actual character, thus causing an error when you try to get the player from let's say a part. Also, you are missing an end.

thingy.Touched:connect(function(hit)
	if not hit.Parent:findFirstChild("Humanoid") then return end -- Will stop if it is not a player.
	player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player.TeamColor == game.Players.LocalPlayer.TeamColor then
		return false
	else
		player.Character.Humanoid:TakeDamage(5)
	end -- Missing end
end)

[NOT ANSWER] MAKE SURE YOU USE THE LUA BUTTON TO MAKE IT LOOK LIKE A SCRIPT! THANKS

1 comment

0

Ok sorry. This is only my second question on here.

First, is it in a weapon? Cause it won't work if not.

 local WepDamage = 5 -- For simplicity
 -- Weapon script (Anims, etc)
 thingy.Touched:connect(function(hit)
 if not hit.Parent:findFirstChild("Humanoid") then return end
 player = game.Players:GetPlayerFromCharacter(hit.Parent)
 if player.TeamColor == game.Players.LocalPlayer.TeamColor then
 return false
 else
 player.Character.Humanoid:TakeDamage(WepDamage)
 end
 end)

Try that.

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