The function "IsANPC" keeps failing to work and returns false not just that it prints twice,why?
Output:
false
false
false
false
Part has a Humanoid
Part has the value NPC
Part has a String Value
false
Part has a Humanoid
Part has the value NPC
Part has a String Value
Part has a Humanoid
Part has the value NPC
Part has a String Value
Script:
--[[Purpose:I'm making a script that is finding npcs with the value "Shop"
and making them into a shop]]--
--Part = Instance.new("Part",game.Workspace)
--Humanoid = Instance.new("Humanoid",Part)
--Value = Instance.new("StringValue",Part)
--Value.Name = "NPC"
--Value.Value = "Shop"
ShopNPCs= {}
Functions = {
IsAShopNpc = function(Part)--Used to justify if it's a Shop Npc
if Part:FindFirstChild("Humanoid") then
print(Part,"has a Humanoid")
local Value = Part:FindFirstChild("NPC")
print(Part,"has the value NPC")
if Value then
if Value:IsA("StringValue") then
print(Part,"has a String Value")
if Value.Value== "Shop" then
print(Part,"contains the Value Shop")
return true
else return false
end
end
end
end
end,}
for _,Object in pairs (game.Workspace:GetChildren()) do
if Functions.IsAShopNpc(Object) then
table.insert(ShopNPCs,Object)
elseif not Functions.IsAShopNpc(Object) then
assert(false,"is not a NPC")
end
end
If the part has all these qualities why isn't it returning true and why is it printing it twice?
How could I fix this?

3 comments
Thanks,you helped me find the problem I mean't to put Value.Value.
Why does it assert only once?Shouldn't it print twice since its on a loop?
If you are referring to line 35, calling assert with a false or nil first argument will cause an error, stopping the script. You should change it to a print statement.