Why my script don't see npc?

Hi i have a script that should check the last thing who touched part but this script don’t see an npc.
I made a print example so i can see if npc even visible for script but its doesnt respond for npc but when i moving through part it see me :frowning:
Heres script:

local part = script.Parent


local function onPartTouchEnded(hit)
	print(hit.Parent.Name)
	print(hit.Name)
	if hit.Parent.Name == part.Name then
		part.Ready.Value = true
	end
end

part.TouchEnded:Connect(onPartTouchEnded)
2 Likes

Is the NPC’s name the same as the part’s? I don’t see why that would be the case.

You can find if the hit is from an npc if game.Players:GetPlayerFromCharacter(hit.Parent) returns nil and hit.Parent:FindFirstChild("Humanoid") returns true.

yes the names are the same (30 characters needed)

Are you sure? I just tested comparing a dummy’s name to a part and it worked just fine. Could your dummy name have white space? Either way, it would be better practice to use what I have above, as it’s not dependent on names of objects.

i tryed this method still nothing. maybe it don’t see npc because my another script just destoroys npc?

Is the npc generated in a LocalScript?

nope this npc isnt local (30 charrrs)

Can you show us what it looks like in the explorer?

Screenshot_181 Screenshot_182

1 Like

When you say npc, I assume you mean imported for the built in rig-builder?
image

Does the npc have a Humanoid as a child to it? The code I have above looks for a humanoid, and makes sure its not a real player touching it.
image

I might be wrong, but I believe that script has to be a LocalScript.

yes i take my npc template from this plugin

local scripts dont work in workspace

.Touched events in LocalScripts only run with the client touches it. To find an npc this has to be server.

LocalScripts do work in Workspace.

Ah, I rarely use .Touched events haha

im not sure but maybe it don’t work as i have a part that cover the whole npc? i don’t know really

Can you try touch the part and then stop touching it? It says TouchEnded here.

workspace.Part.Touched:Connect(function(hit)
	local npc = hit.Parent
	if npc:FindFirstChild("Humanoid") and not game.Players:GetPlayerFromCharacter(npc) then
		print("An npc has touched the brick.")
	end
end)

This is exact code I used to detect an npc, and it works fine? Does the npc have a Humanoid inside of it?
image

it works for players, but its looks like script just don’t see npc