Cannot set the transparency of parts for a specific client if they are out of render distance

For context I am creating a 2 player obby and each player is assigned a colour, they can only stand on platforms that match their colour. To convey this to the players I have made a system that makes all parts of the opposite colour slightly transparent.

However this system only applies this to all parts that are currently within the players render distance meaning after they progress through the obby, the parts that were not previously loaded will be loaded and are not transparent.

I have attempted to send all the parts from the server using a remote function, however parts that are not loaded in either don’t show up or appear as “nil”

I haven’t been able to find any forums about this so I decided to make a post. I would want to make a system that sets the transparency of the parts as they load in but I don’t know of the best way to do that

client side scripts

Initial Client-Side method
local blueCollisionParts = game.Workspace.BlueCollisionParts:GetChildren()
local redCollisionParts = game.Workspace.RedCollisionParts:GetChildren()

local function SetTransparency(plrNum)
	--Fetching parts from server
	local blueCollisionParts = GetColouredParts:InvokeServer("Blue")
	local redCollisionParts = GetColouredParts:InvokeServer("Red")
	
	print(redCollisionParts, #redCollisionParts ,blueCollisionParts , #blueCollisionParts)
	
	if plrNum == 1 then
		for i = 1, #blueCollisionParts do
			blueCollisionParts[i].Transparency = 0.4
		end
		for i = 1, #redCollisionParts do
			redCollisionParts[i].Transparency = 0
		end
	else
		for i = 1, #redCollisionParts do
			redCollisionParts[i].Transparency = 0.4
		end
		for i = 1, #blueCollisionParts do
			blueCollisionParts[i].Transparency = 0
		end
	end
end

SetTransparencyEvent.OnClientEvent:Connect(SetTransparency)

server side script

local redParts = game.Workspace.RedCollisionParts:GetChildren()
local blueParts = game.Workspace.BlueCollisionParts:GetChildren()
local GetColouredParts = game.ReplicatedStorage.RemoteEvents.GetColouredParts

local function sendColouredParts(plr, colour)
	print(colour)
	if colour == "Blue" then
		return blueParts
	elseif colour == "Red" then
		return redParts
	end
end
	
GetColouredParts.OnServerInvoke = sendColouredParts

This is a StreamingEnabled issue and because the user is so distant from the parts Roblox will not load in the parts.

You can detect the parts loading in using workspace.Parts.ChildAdded event or detect when they are removed by using workspace.Parts.ChildRemoved - and when either of these call you could re-update the parts and re-run your function to change the transparency.

Or a simple work around is to set the streaming mode to Persistent for all the parts that you wish to change the transparency of (read this ModelStreamingMode | Documentation - Roblox Creator Hub).

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