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

How to get NPC to Chase Team or Brick Color?

Asked by 4 years ago
Edited 4 years ago

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

1 answer

Log in to vote
0
Answered by 4 years ago

I do not think you can change the team of an NPC since it isn't an actual player.

0
I wasn't trying to get the NPC to be on a team. I was trying to get it to chase a specific team color. AngeloidX3 0 — 4y
0
Oh, sorry. I read the title as if it said "How to get NPC to Change Team or Brick Color?" youtubemasterWOW 2741 — 4y
0
Lol you're good AngeloidX3 0 — 4y
Ad

Answer this question