so basically I have a gun and I want the shots to not deal damage if the two players are on the same team. I have tried using equal to and not equal to but they both don’t work. I’ve tried using both Team and TeamColor and they both don’t work. Whenever I open a Local Server people who are on the same team still take damage and the “deal no damage” doesn’t print.
Code I'm using, there is obviously more code around it (the reason I'm using Player1 and Player2 is just to make testing easier at the moment)
local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
if game.Players.Player1.TeamColor == game.Players.Player2.TeamColor --this is probably the broken part
then print ("deal no damage")
else humanoid:TakeDamage(10) -- Damage.
Simple! Just find out who the player is from the hitPart;
local Players = game:GetService("Players")
local Player = nil --how are you defining the player who shot the projectile?
if hit.Parent:FindFirstChild("Humanoid") then
local PlayerFromHit = Players:GetPlayerFromCharacter(hit.Parent)
if PlayerFromHit then
if PlayerFromHit.Team ~= Player.Team then
--damage because they're not on the same team
--no damage because they're on the same team
I am assuming you’re checking if the part is hit, which is why I didn’t provide anything else. If you know how you’re defining the player who shot the weapon, then just put the Player variable to that, and use the same checks I have implemented for you, then do the damage related stuff.
oh yeah… I forgot that whenever you equip a tool it’s removed from your backpack, Is there a way to get player from character? or are there other ways to define player?
this is NOT a local script by the way