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?
On line 21, you have if Value == "Shop" then
, but this will never be true. Did you mean if Value.Name == "Shop" then
?
Minor note: you could just have a single "return false" at the end of the function IsAShopNPC (ie right after line 31) instead of having "else return false" scattered throughout the rest of the function.