Question about StreamingEnabled and how to get distant parts

Hi! Just a small question about StreamingEnabled. I have recently enabled it in my game but I encounterd a minor problem. When I am far away from parts they load out (I know this is what streaming does) and I want to know how to still access them. The documentation said to use :WaitForChild() but this just infinite yields. Do any of you have any suggestions on how I can still access this part?

1 Like

Have you tried putting the parts into a model?

I think if you turn streamingEnabled off then it will stay on your screen. but if you keep it on then you will probably keep having that problem. Otherwise its just good for optimization. if you want to get the waitforchild not to infinite yield Just do WaitForChild(“Part”, math.huge). Also you could just use a server script, Because you cant access a part once its not loaded on the client.

Just tried, still does not work. When I move too far away they are unloaded (They despawn in the explorer also)

WaitForChild(“Part”, math.huge) would still not get the part? Argument #2 is just a Time Out variable. Till I get more info on the matter StreamingEnabled will be disabled

This is what CollectionService is built for, with a handy code example on how to use it.

You essentially “tag” Instances with a string, and if these Instances gets streamed in and out, it will trigger the GetInstanceAddedSignal and GetInstanceRemovedSignal. This allows you to hook and unhook functions to your parts.

Alternatively, you can read up on the article regarding instance streaming and use persistent models if you want to go this direction.

1 Like

You can also use RequestAreaStreaming to load the parts around a set position, it does require setting up a RemoteEvent that sends the desired object path to the server.

Ex:
Server

local loadEvent = game.ReplicatedStorage.LoadEvent

local function load(plr, obj)
	local objResult = nil
	for i = 1, #obj do
		if not objResult then
			objResult = game.Workspace[obj[i]]
		else
			objResult = objResult[obj[i]]
		end
	end
	if objResult ~= nil then
		plr:RequestStreamAroundAsync(objResult.Position)
		return objResult
	end
end

loadEvent.OnClientEvent:Connect(load)

Client

local loadEvent = game.ReplicatedStorage.LoadEvent

local objPath = {
	"Model",
	"Part"
}

loadEvent:FireServer(objPath)

local Model = game.Workspace:WaitForChild('Model')
local Part = Model:WaitForChild('Part')

Using persistent models would be much easier but you can use this to temporarily load an object if the persistent model is taking a toll on the game.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.