Ep 7. Waiting for Spawn Location

During this episode of the Super Simple Obby series, we created the Get Spawn Location function inside of the Stages config module script. We want to make a small adjustment to this function in order to prevent any possible errors from arising in the future, mostly due to having Streaming Enabled turned on.

We implement a Rebirth feature in future episodes, which will teleport the player from the last stage to the very first stage of our Obby. Since we use Streaming Enabled, there is a chance that the first stage isn’t currently being streamed to the player, when they’re at the very last stage. So what some have experienced is that upon rebirthing an “Infinite yield possible” error is being thrown because the first stage hasn’t been streamed in yet.

This can be easily solved by specifying the maximum amount of time we should wait for the specific spawn location. We’ll set this number to about 10, which gives the player about 10 seconds for the spawn location to be streamed in. I believe that 10 seconds will be fine for players with even the worst internet connection, but you could choose to wait longer.

Script

ReplicatedStorage/Configs/Stages.lua
...

function Shared.GetSpawnLocation(stage: number)
	local stageFolder: Folder = Workspace.Stages[stage]
	local spawnLocation = stageFolder:FindFirstChildOfClass("SpawnLocation")
	if not spawnLocation then
		spawnLocation = stageFolder:WaitForChild("SpawnLocation", 10)
	end
	
	return spawnLocation
end

...
Contents