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

?I am trying to make my model to attack different team. Help?

Asked by 8 years ago
Edited 8 years ago

Good day, I tried to locate and check distant, character, and team color.

for _,v in ipairs(game.Players:GetPlayers())do

    if v.Character and v.TeamColor == BrickColor.new("For hire") and v:DistanceFromCharacter(h.Position)<dis then
        dis,pl=v:DistanceFromCharacter(h.Position),v
    end

But, it won't work.

When I do this, it works, but it attack anyone it see.

for _,v in ipairs(game.Players:GetPlayers())do

    if v.Character and v:DistanceFromCharacter(h.Position)<dis then
        dis,pl=v:DistanceFromCharacter(h.Position),v
    end

I need to find team color. What did I do wrong?

2 answers

Log in to vote
1
Answered by
tkcmdr 341 Moderation Voter
8 years ago
Edited 8 years ago

Hey Asher0606!

When determining the TeamColor, you have to use a valid BrickColor (i.e. Really red, New yeller.) 'For Hire' may be the name of the team, but it is NOT its color.

Your code fails because 'For Hire' is not a valid color. Instead, use the BrickColor of the team. If the color of the team is Light stone grey, use BrickColor.new("Light stone grey").

Have a nice day, and best of luck with your game!

Best regards, tkcmdr

Edit: Fixed formatting

Ad
Log in to vote
0
Answered by 8 years ago

if v.Character and v:DistanceFromCharacter(h.Position)<dis then dis,pl=v:DistanceFromCharacter(h.Position),v end if pl.TeamColor ~= BrickColor.new('YourBrickColor') then --attack else --dont attack end

-- Didn't test this but thats the basic concept. -- Hope I helped.

Answer this question