Engine Bug: Client Destroying things and making Script Error

Okay, so I have a client script where it goes through every thing in the folder, there is the script.

local function SetUp()
	local Prox = {}

	for _, shop in pairs(shops:GetChildren()) do
		local NPC = shop:WaitForChild("NPC")
		local HumanoidRootPart = NPC:WaitForChild("HumanoidRootPart")
		local ProximityPrompt = HumanoidRootPart:FindFirstChild("Shop")

		table.insert(Prox, ProximityPrompt)
	end

	return Prox
end

This is the error I am getting.

I know what’s the problem too. The problem is because the client is destroying things that aren’t around. For more FPS. My map is pretty big and when it does this it means you can access the HumanoidRootPart. Can anyone at Roblox Staff make a Number to where we can add it to where it can delete parts in a certain number?

Or a code fix that could help and fix the problem here, cause this will break my game.

4 Likes

If anyone wants to see the Hierachy of what it looks like when your away, here it is.

image

1 Like

Inside of the NPC model there is no part called HumanoidRootPart…

2 Likes

Yea, because when your far away it deletes it (For more FPS) and when you go back towards it. It puts it back.

That picture wasn’t in the Edit Mode. That was in the Run Mode

Do you have streaming enabled inside of your game?

Yes I do. Does that fix the problem?

Turning it off will most likely fix the problem but if you want to keep streaming enabled on for whatever reason then you will have to look for another way. One way that might work is making the ModelStreamingMode to be persistent or something.

Here is some documentation on it.

1 Like

Okay, so I have a LoadingScreen ( that actually works lol ) would that fix the problem turning it off and having the LoadingScreen preload everything?

1 Like

Maybe just turn streaming enabled off fully and then turn it back on once you learn more about it and know how it works. It basically just loads parts in and out depending how close players are to help with performance. But this requires some adjustments.

If the HumanoidRootPart is in a destroyed state when the function runs, it will return an infinite yield possible. Could that be the issue?