Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

gun that is non Friendly Fire?

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

2 answers

✓ Accepted answer

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

1 comment

0

Thanks it works now :)

This discussion is preserved as it was. New answers, comments, and votes are closed.