Basically, I’m making a NPC that will fight NPCs of diffrent team colors, I have it detect every NPC in the workspace, And using a data folder detect who is what team.
It says the npc himself is an ally (Which is good, It detects that its on its own team)
But when i add another NPC of the same exact color, It appears to think it’s an enemy.
GIF of me placing 2 NPCs of the same team, But them thinking the other are enemies: https://gyazo.com/b956f326b44a767fce7edc5620c62a16
(The 2 lines that say “Swordsman Friendly” are the NPCs saying they themselves are friendly to theirselves, The lines that say “Swordsman Enemy” Are the NPCs saying the other NPC is an enemy to them.)
Code used to determine if other NPCs are enemies or allies:
(TeamColor is a BrickcolorValue)
for _,Npc in pairs(workspace:GetDescendants()) do
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print(Npc.Name, "Enemy")
else
table.insert(AllyTable, Npc)
print(Npc.Name, "Friendly")
end
end
end
workspace.ChildAdded:Connect(function(Npc)
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print(Npc.Name, "Enemy")
else
table.insert(AllyTable, Npc)
print(Npc.Name, "Friendly")
end
end
end)
I remember having to come across Team Filtering aha
Could you try printing what every NPC’s TeamColor value is supposed to be? Maybe that’ll clear up a bit more info
for _,Npc in pairs(workspace:GetDescendants()) do
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print(Npc.Name, "Enemy", script.Parent.Data.TeamColor.Value)
else
table.insert(AllyTable, Npc)
print(Npc.Name, "Friendly", script.Parent.Data.TeamColor.Value)
end
end
end
workspace.ChildAdded:Connect(function(Npc)
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print(Npc.Name, "Enemy", Npc.Data.TeamColor.Value)
else
table.insert(AllyTable, Npc)
print(Npc.Name, "Friendly", Npc.Data.TeamColor.Value)
end
end
end)
Hm, maybe it could be the order you put your script in? I don’t think it’d make any difference but try this:
for _,Npc in pairs(workspace:GetDescendants()) do
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value == script.Parent.Data.TeamColor.Value then
table.insert(AllyTable, Npc)
print(Npc.Name, "Friendly", script.Parent.Data.TeamColor.Value)
elseif Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print(Npc.Name, "Enemy", script.Parent.Data.TeamColor.Value)
else
print("Um w h a t")
end
end
end
workspace.ChildAdded:Connect(function(Npc)
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value == script.Parent.Data.TeamColor.Value then
table.insert(AllyTable, Npc)
print(Npc.Name, "Friendly", script.Parent.Data.TeamColor.Value)
elseif Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print(Npc.Name, "Enemy", script.Parent.Data.TeamColor.Value)
else
print("Um w h a t")
end
end
end)
It is still the exact same, I’m starting to think it’s brickcolorvalue that’s bugged?
Since my NPC placement system should have changed the color but didnt.
Ok so I did a bit of debugging, and I put this script inside 2 dummies:
local AllyTable = {}
local EnemyTable = {}
for _,Npc in pairs(workspace:GetChildren()) do
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value == script.Parent.Data.TeamColor.Value then
table.insert(AllyTable, Npc)
print("Allies:")
print(AllyTable)
elseif Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print("Enemies:")
print(EnemyTable)
else
print("Um w h a t")
end
end
end
workspace.ChildAdded:Connect(function(Npc)
if Npc:FindFirstChild("Humanoid") and Npc:FindFirstChild("Data") then
if Npc.Data.TeamColor.Value == script.Parent.Data.TeamColor.Value then
table.insert(AllyTable, Npc)
print("Allies:")
print(AllyTable)
elseif Npc.Data.TeamColor.Value ~= script.Parent.Data.TeamColor.Value then
table.insert(EnemyTable, Npc)
print("Enemies:")
print(EnemyTable)
else
print("Um w h a t")
end
end
end)
I went ahead & ran the simulation, and this is what I got:
I first put a regular friendly Dummy in the workspace, and this is what outputted:
Next I put a Evil Dummy in the workspace, and this is what outputted instead:
First line is the Friendly Dummy’s Enemies
Second line is the Evil Dummy’s Enemies
Third line is the Evil Dummy’s Allies
If it sounds confusing, you could try the script I debugged & see what you get when you have a chance?