I am making a gun that works right now perfectly fine but i try to make it non friendly fire but i keep getting error "TeamColor is not a vaild member of model"
This is my code
function Damage(Part) if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.TeamColor ~= Player.TeamColor then Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -Dmg end end
You're problem is that part.Parent is not the Player, but the character. The player has the property TeamColor whereas the character does not. Thankfully there is a simple solution, the method GetPlayerFromCharacter. You can implement it like so:
function Damage(Part) if Part.Parent:FindFirstChild("Humanoid") ~= nil and game.Players:GetPlayerFromCharacter(part.Parent).TeamColor ~= Player.TeamColor then Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -Dmg end end