Does this script break with content streaming? (Local Remote Event)

It’s a script that manually emits particle.

RemoteEvents:WaitForChild("EmitParticle").OnClientEvent:Connect(function(Particle)
	
	local Rate

	if typeof(Particle) == "table" then -- If the event got a table of Particles then get rate of one instance in table
		
		Rate = 1 / Particle[1].Rate
		
	else -- Else, get the rate of the singular Particle
		
		Rate = 1 / Particle.Rate
		
	end
	
	while Particle do
		wait(Rate)
		if typeof(Particle) == "table" then -- If table then iterate, then emit
			if not Particle[1] then -- If the ParticleEmitters have been deleted, Break loop
				
				break

			else
				for _, p in ipairs(Particle) do
					
					p:Emit(1)
					
				end
			end
		else -- If instance then emit
			
			Particle:Emit(1)
			
		end
	end

	Particle = nil

end)

I want to script with streaming enabled, but it’s so annoying doing anything in the client, I never know if i have access to something or not to something in the workspace, and i can’t find a foolproof way of getting it.

The :WaitForChild() method already works. You’re not executing the code until the RemoteEvents is loaded.

However, the way you’re firing the EmitParticle within (an instance I’m not sure if it’s a part or folder) and sending the Particle argument you would need a waitforchild too (I don’t see what code fires the event so I’m assuming you did that).

Particle is a table of particle emitters, or a single particle emitter, they’re inside the player character.
Also does :WaitForChild() stream in parts that have been streamed out? My understanding is that you had to use Player:RequestStreamAroundAsync(), or is that only in the server?

:WaitForChild() is used in the client to wait until the part is streamed and then the code is ran. In other words, if you do game.Worskspace:WaitForChild(“Part”) you’re pausing that script until Part is streamed in the player’s client.

Player:RequestStreamAroundAsync() is used to manually load a region of the workspace in the given player’s client, even if the player isn’t in that region

If you still got any confusion (I get you lol because I had trouble understanding this a while ago) I can help

1 Like

Alright, WaitForChild waits for the basepart to be streamed in. But does it load the part in? Or do i have to do that too. If i have to, then should i use Player:RequestStreamAroundAsync()?

Player:RequestStreamAroundAsync(Position of Part)

local Part = workspace:WaitForChild("Part")

Q: But does it load the part in?
A: No, WaitForChild does all its name implies. It waits for the part to be streamed. It only waits.

For the second question, if you wanted the code to run without the player in the part’s range, then you should RequestStreamAroundAsync. For example, if your player is at origin (0, 0, 0) but the Part is at (1000, 1000, 1000) and the streaming range is 100, and you want the script within the Part (with the WaitForChild) to run, then yes, you would either need use RequestStreamAroundAsync or wait until the player walks into the range.

Basically there’s certain visual effects that i don’t want to do on the server. So only players within 800 studs will run those scripts locally, is RequestStreamAroundAsync the appropriate way of doing that? Also do you personally think 800 studs is too much?

Q1
In your case, RequestStreamAroundAsync wouldn’t be needed, since players automatically load the part when they’re within 800 studs. In this case, the visuals will only run on the client side when they’re within 800 studs.

(other scenario for info ig) If you wanted the part to be loaded outside of 800 studs then RequestStreamAroundAsync would be needed.

Q2
Depending on how detailed your map generally is. Remember, streaming enabled is for loading and unloading physical parts that aren’t interacted or seen by the client to save memory to prevent lag.

If you have a flat terrain with a few trees here and there, 800 studs on mobile is good. On the other hand, if you’re doing shadows and visuals or have a London Metropolis, then 200 studs is already a lot to handle for mobile.