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 10 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
10 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 10 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 — 10y
Log in to vote
-1
Answered by 10 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