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?
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
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.