Below is the code in a local script to check if an npc has a bool value (named Finished) set to false. Each NPC has a unique name. It works perfectly for a while then I get the error “Finished is not a valid member of Model Workspace.NPCsInWorld.Rig(R15)78”
local function GetNPCWhiteList()
local Whitelist = {}
for i, Model in pairs(game.Workspace.NpcsInWorld:GetChildren()) do
if Model.Finished.Value == false then
for i,modelpart in pairs(Model:GetDescendants()) do
if modelpart:IsA("BasePart") or modelpart:IsA("Part") then
Whitelist[#Whitelist+1] = modelpart
end
end
end
end
return Whitelist
end
I understand that this error means the bool value doesn’t exist on the client, but I don’t know why. This is how the NPCs are created on the Server:
local namenum = 0
NPCModule.CreateNPC = function(player)
local profile = PlayerDataCache[player]
if profile then
local Model
local num = math.random(1,#game.ReplicatedStorage.NPCS.Defaults:GetChildren())
for i,v in ipairs(game.ReplicatedStorage.NPCS.Defaults:GetChildren()) do
if i == num then
Model = v:Clone()
end
end
for i,v in pairs(Model:GetDescendants()) do
if v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") then
PhysicsService:SetPartCollisionGroup(v,"NPCs")
end
end
Model:WaitForChild("Finished")
print("Finished waiting")
namenum += 1
Model.Name = Model.Name..namenum
Model.Parent = game.Workspace.NpcsInWorld
local humanoid = Model:WaitForChild("Humanoid")
PlayAnimationForHumanoid:FireAllClients(humanoid)
humanoid.WalkSpeed = math.random(6,9)
end
end
I removed the irrelevant bits. As you can see, the bool value exists in the models I clone, and I even go out of the way to wait for it. Idk why the client eventually fails to find it.