So, what I did was put
local Players = game:GetService("Players") local Teams = game:GetService("Teams") for_,Player = pairs(Players:GetChildren()) do if Player.TeamColor == "Bright red" then BrickColor.new("Bright red") end end
in StarterPlayerScripts so the player would get a brickcolor when on red team
I'm trying to get the NPC to chase the Bright red team color or brickcolor. Couldn't figure out team color so I'm trying to do this brick thing.
This is the code in the NPC, it's not all mine I looked up things for help. but I've tried adding the brickcolor in to get it to chase that.. There's absolutely no errors but nothing happens.
local Players = game:GetService("Players") local Teams = game:GetService("Teams") function findNearestPlayer(Position) wait (0.3) local List = game.Workspace:children() local Torso = nil local Distance = 1000 local Temp = nil local Human = nil local Temp2 = nil for x = 1, #List do Temp2 = List[x] if (Temp2.className == "Model") and (Temp2 ~= script.Parent) and game.Players:FindFirstChild(Temp2.Name) and BrickColor.Name == "Bright red" then Temp = Temp2:findFirstChild("HumanoidRootPart") Human = Temp2:findFirstChild("Humanoid") if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then if (Temp.Position - Position).magnitude < Distance then Torso = Temp Distance = (Temp.Position - Position).magnitude end end end end return Torso end while true do local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
idk if I'm putting something in the wrong area, not deleting something, not adding something right, or if any of this is near correct..
If I try TeamColor I do
local Players = game:GetService("Players") local Teams = game:GetService("Teams") function findNearestPlayer(Position) wait (0.3) local List = game.Workspace:children() local Torso = nil local Distance = 1000 local Temp = nil local Human = nil local Temp2 = nil for x = 1, #List do Temp2 = List[x] if (Temp2.className == "Model") and (Temp2 ~= script.Parent) and game.Players:FindFirstChild(Temp2.Name) and player.TeamColor.Name == ("Bright red") then Temp = Temp2:findFirstChild("HumanoidRootPart") Human = Temp2:findFirstChild("Humanoid") if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then if (Temp.Position - Position).magnitude < Distance then Torso = Temp Distance = (Temp.Position - Position).magnitude end end end end return Torso end while true do local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
Then I get an error 11:24:36.442 - Workspace.Granny.follow:14: attempt to index nil with 'TeamColor' 11:24:36.443 - Stack Begin 11:24:36.444 - Script 'Workspace.Granny.follow', Line 14 - function findNearestPlayer 11:24:36.444 - Script 'Workspace.Granny.follow', Line 33
I do not think you can change the team of an NPC since it isn't an actual player.