local Ray = Ray.new(Character.BodyHead.CFrame.p, (Mouse.Hit.p - Character.BodyHead.CFrame.p).unit * 999) local Ignore = {Player.Character, Camera} local PartHit, PositionHit = Workspace:FindPartOnRayWithIgnoreList(Ray, Ignore) if PartHit and PartHit.Parent:FindFirstChild("Humanoid") then PartHit.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end; if PartHit and PartHit.Name=="Main" then PartHit.Parent.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end; if PartHit and PartHit.Name=="Part" then PartHit.Parent.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end;
local Ray = Ray.new(Character.BodyHead.CFrame.p, (Mouse.Hit.p - Character.BodyHead.CFrame.p).unit * 999) local Ignore = {Player.Character, Camera} local PartHit, PositionHit = Workspace:FindPartOnRayWithIgnoreList(Ray, Ignore) if PartHit and PartHit.Parent:FindFirstChild("Humanoid") then if not game.Players:GetPlayerFromCharacter(PartHit.Parent).TeamColor == player.TeamColor then PartHit.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end end; if PartHit and PartHit.Name=="Main" then PartHit.Parent.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end; if PartHit and PartHit.Name=="Part" then PartHit.Parent.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end;
Part changed :
if not game.Players:GetPlayerFromCharacter(PartHit.Parent).TeamColor == player.TeamColor then PartHit.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage)) end
Uses the :GetPlayerFromCharacter method to find the player from the part, then compares the teamcolor of the player to the person firing (assuming the person firing is saved in a variable named player). The not at the beginning of the if statement indicates that the statement will return true if the opposite happens so the statement is equivalent to game.Players:GetPlayerFromCharacter(PartHit.Parent).TeamColor ~= player.TeamColor
Lastly, use Part.Parent:FindFirstChild("Humanoid") instead of Part.Parent.Humanoid because it can error