Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this anti team kill script not work?

Asked by 9 years ago

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

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
9 years ago

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)
Ad
Log in to vote
-1
Answered by 9 years ago

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

0
Ok sorry. This is only my second question on here. Theepicpaintballer5 0 — 9y
Log in to vote
-1
Answered by 9 years ago

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.

Answer this question