Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

gun that is non Friendly Fire?

Asked by
Kryddan 261 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

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
0
Thanks it works now :) Kryddan 261 — 9y
Ad
Log in to vote
0
Answered by
xp3000 0
9 years ago

no problem glad i could help

Answer this question