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) `
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
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.