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
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)
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.
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.
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?