How can I detect if a humanoid NPC has no tag?

Hello Developers.

As the title says, how can I detect if a humanoid NPC has no tag?

1 Like

Can you explain more on what you mean by “tag?”
Do you mean tag as in how CollectionService uses tags?

1 Like

Yeah, I think? Basically, I got this batter handler script in ServerScriptService. Anyway, the script also controls the movement of the battler depending if they are an enemy or not (Enemies move right while friendly battlers move right).

I want it so that the battler stops moving if they don’t have a tag or doing an action (such as fighting). I also want it to move in opposite directions if their tag got changed. (For example, if an enemy battler somehow becomes a friendly battler, it will move to the right rather than moving to the left.)

EDIT: I forgot the script woops

local RP = game:GetService("ReplicatedStorage")
local BATTLERSFOLDER = RP:WaitForChild("BATTLERS")
local SUMMON_UNITEVENT = RP:WaitForChild("SUMMON_UNIT")

--//Friendly
SUMMON_UNITEVENT.OnServerEvent:Connect(function(plr, Wishedunit)
	local ifUnitExist = BATTLERSFOLDER:FindFirstChild(Wishedunit)
	
	if ifUnitExist then
		local existingBattler = ifUnitExist:Clone()
		--Positioning
		existingBattler.Parent = workspace.ExistingEntities
		existingBattler:WaitForChild("HumanoidRootPart").CFrame = workspace.Spawn.CFrame + Vector3.new(0, 3, 0)
		--Team
		existingBattler:AddTag("FriendlyTag")
		
		for _, bodypart in pairs(existingBattler:GetChildren()) do
			if bodypart:IsA("BasePart") then
				bodypart.CollisionGroup = "NPCs"
			end
		end
		--existingBattler.Humanoid:Move(Vector3.new(-1, 0, 0))
	elseif not ifUnitExist then
		warn(plr.Name.." tried requesting a non-existant battler.")
	end
end)
--//Enemies
--TBA
--//Movement
while task.wait(0.5) do
	for _, Entities in pairs(workspace.ExistingEntities:GetChildren()) do
		if Entities:IsA("Model") then
			local Hum = Entities:WaitForChild("Humanoid")
			
			if Entities:HasTag("FriendlyTag") then
				Entities.Humanoid:Move(Vector3.new(-1, 0, 0))
			elseif Entities:HasTag("EnemyTag") then
				Entities.Humanoid:Move(Vector3.new(1, 0, 0))
			end
		end
	end
end
1 Like

To see if an Instance has no tags, do

if #Instance:GetTags() == 0 then
1 Like

Did I do it correctly?

--//Movement
while task.wait(0.5) do
	for _, Entities in pairs(workspace.ExistingEntities:GetChildren()) do
		if Entities:IsA("Model") then
			local Hum = Entities:WaitForChild("Humanoid")
			
			if #Entities:GetTags() == 0 then
				Hum:Move(Vector3.new(0, 0, 0))
			else
				if Entities:HasTag("FriendlyTag") then
					Entities.Humanoid:Move(Vector3.new(-1, 0, 0))
				elseif Entities:HasTag("EnemyTag") then
					Entities.Humanoid:Move(Vector3.new(1, 0, 0))
				end
			end
		end
	end
end
1 Like

Yeah that would be correct. Should work as expected

1 Like

When I try removing the battler’s FriendlyTag via the Command Bar when testing, it didn’t work as he kept moving.

1 Like

Make sure you’re doing that on the server, or whatever context your script is.

1 Like

The handler for that script is in ServerScriptService.

1 Like

As mentioned, make sure you’re in server mode when executing the command in the command bar. If you’re not sure that’s the way to check if an Instance has no tags, call

print(#workspace:GetTags())

or on any other non-tagged Instance.

1 Like

Or you could add an else that should run if the NPC doesn’t have any of the specified tags.

1 Like

How can I do that?

{filller aaaaaay}

1 Like

Just… add an else case in that if block that runs this?

1 Like

So like this?

while task.wait(0.5) do
	for _, Entities in pairs(workspace.ExistingEntities:GetChildren()) do
		if Entities:IsA("Model") then
			local Hum = Entities:WaitForChild("Humanoid")
			
			if Entities:HasTag("FriendlyTag") then
				Entities.Humanoid:Move(Vector3.new(-1, 0, 0))
			elseif Entities:HasTag("EnemyTag") then
				Entities.Humanoid:Move(Vector3.new(1, 0, 0))
			else
				Entities.Humanoid:Move(Vector3.new(0, 0, 0))
			end
			
		end
	end
end
1 Like

Yes. Now test the NPCs and see if that works

1 Like

Sadly doesn’t work.

{djqhueqowheuqqhieuhiqewuhewui filler}

1 Like

Add a print in each of the checks to see if they work. Add a print in the loop and above to see if it runs.

1 Like

Dammit, it still won’t work.

{god damn this stupid filler}

Can you share the current code, with prints, and tell which ones get in the output?

I’ll send you the code for it later.