Players will see the void when spectating for too long

Basically in my game, the players will go through a randomly generated tunnel. Upon death, they will enter spectator mode. Since the players always keep going forward, at some point, they will go far from where the spectator died, and, in the end, will result in this.


Everything around will be unloaded.

Now, I tried to fix this using StreamingEnabled, but that doesn’t seem to help at all. Here’s the code:

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local remotes = ReplicatedStorage:WaitForChild("Remotes")
local loadAround = remotes:WaitForChild("RequestLoading") --the remote that requests to load around the player

local camera = workspace.CurrentCamera
workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function()
	local newCam = workspace.CurrentCamera
	if newCam then
		camera = newCam
	end
end)

local function playerList()
	local list = Players:GetChildren()
	table.remove(list, table.find(list, player))
	local newList = {}
	for i, p:Player in ipairs(list) do
		local char = p.Character
		if char then
			local hum = char:FindFirstChildWhichIsA("Humanoid")
			if hum then
				if hum.Health > 0 then
					table.insert(newList, p)
				end
			end
		end
	end
	return newList
end

local frame = script.Parent
local gui = frame.Parent
local prevBtn = frame:WaitForChild("Previous")
local nextBtn = frame:WaitForChild("Next")
local spectatingText = frame:WaitForChild("Current")

local spectating = nil

player.CharacterAppearanceLoaded:Connect(function(char)
	spectating = nil
	gui.Enabled = false
	
	char:WaitForChild("Humanoid").Died:Connect(function()
		gui.Enabled = true
	end)
end)

prevBtn.Activated:Connect(function(inpObj, cc)
	local list = playerList()
	local ind = table.find(list, spectating) or 2
	local newInd = ind - 1
	if newInd <= 0 then
		newInd = #list
	end
	spectating = list[newInd]
end)

nextBtn.Activated:Connect(function(inpObj, cc)
	local list = playerList()
	local ind = table.find(list, spectating) or 0
	local newInd = ind + 1
	if newInd > #list then
		newInd = 1
	end
	spectating = list[newInd]
end)

local lastReq = tick()
RunService.Stepped:Connect(function(t, dt)
	local list = playerList()
	
	if table.find(list, spectating) == nil and spectating ~= nil then
		spectating = list[1]
	end
	
	if spectating and spectating.Character then
		if tick()-lastReq > 1 then
			lastReq = tick()
			loadAround:FireServer(camera.CFrame.Position)
		end
		spectatingText.Text = spectating.Name
		camera.CameraSubject = spectating.Character:WaitForChild("Humanoid")
	else
		spectatingText.Text = "None"
		camera.CameraSubject = player.Character:WaitForChild("Humanoid")
	end
end)

gui:GetPropertyChangedSignal("Enabled"):Connect(function()
	if gui.Enabled then
		local list = playerList()
		spectating = list[1]
	else
		spectating = nil
	end
end)

Server side:

local RS = game:GetService("ReplicatedStorage")

local remotes = RS:WaitForChild("Remotes")
local loadAround = remotes:WaitForChild("RequestLoading")

loadAround.OnServerEvent:Connect(function(plr, pos:Vector3)
	plr:RequestStreamAroundAsync(pos)
end)

Thanks in advance.

1 Like

Bump because the issue is still occuring

Have you tried updating the replication focus? Maybe that would help Player | Documentation - Roblox Creator Hub

So I create a part that just follows the player camera, and set the player’s ReplicationFocus to it?

I’m not sure you’d even need to create a new part. You may be able to use the root part of whichever player the spectator is focussed on.

Sorry for the late reply.

Nope, unfortunately the issue still persists.

I should note that this happens only on low end devices or on low graphics quality settings. Switching to high graphics will eventually fix the issue.