How to effectively duplicate a jailsystem while preventing any unneccesarily straining of the game engine?

Hi,

First off: sorry for the super long title, I could not think of a shorter one. I’ll cut right to the chase.

I am currently working on a group game, one of the features I have in mind is being able to see who is in a prison cell from a distance, which eliminates the need to manually check if need be. I have 8 cells and I plan to have this for each cell.

The immediate issue which arises is… the playability of the game. A lot will tend to go down and I can say that having 8 remote events with 8 copies of the same (fairly intense) script will not help the game.

My immediate question/problem is how do I find a way to duplicate the script, remote event and UI without unnecesarily straining the server?

I have tried a possible solution which someone gave me, however I do not think I fully understood his advice. He said to, and I quote: " place all is the parts in a folder or selection box, use get children and then when player steps on one of the children display the info".

I will now paste all the relevant code so that you have maximum insight.

Script responsible for adding/removing players from the cell as well as displaying their info on the screen.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screendisplay = game.Workspace.Screen.SurfaceGui

local JailOccupants = newproxy(true)
local _occupants = {}

local Metatable = getmetatable(JailOccupants)

function Metatable:__newindex(Key, Value)
	_occupants[Key] = Value
	
	if Value then
		if Key.TeamColor ~= BrickColor.new("Mid gray") then
		print(Key.Name.. ' has been added to jail')
		screendisplay.OccupantName.Text = Key.Name
	spawn(function()	
		screendisplay.PlayerPicture.Image = Players:GetUserThumbnailAsync(Key.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size180x180)
	end)
		screendisplay.AccountAge.Text = Key.AccountAge .. "\n Days old."
		screendisplay.AccountId.Text = Key.userId
		screendisplay.Occupant.Text = screendisplay.Occupant.Text .. "\n Name"
		end
	else
		print(Key.Name.. ' has been removed from jail')
	end
end

function Metatable:__index(Key)
	return _occupants[Key]
end

local JailPart = game.Workspace.JailPad
local RemoteEvent = ReplicatedStorage:FindFirstChild("jailevent") or Instance.new("RemoteEvent")
RemoteEvent.Name = "jailevent"
RemoteEvent.Parent = ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(Player)
	local PlayerIsInJail = JailOccupants[Player]
	 
	if Player.Character then
		local Distance = Player:DistanceFromCharacter(JailPart.Position)
		
		if PlayerIsInJail then
			if Distance > 15 then
				JailOccupants[Player] = false
				RemoteEvent:FireClient(Player, false)
				screendisplay.OccupantName.Text = "Empty cell"
				screendisplay.AccountAge.Text = "AccountAge"
				screendisplay.AccountId.Text = "AccountId"
				screendisplay.PlayerPicture.Image = "rbxassetid://2489848149"
			end
		else
			if Distance <= 11 then
				JailOccupants[Player] = true
				RemoteEvent:FireClient(Player, true)
			end
		end
	end
end)

Remote event which checks to see if a player has stepped on a pad. If so, then fill the screen UI properties with their player info

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("jailevent")

while true do
    RemoteEvent:FireServer()
    wait(0.1)
end

Now my question is: Why do you necessarily need 8 scripts and 8 events?

There are a few solutions, perhaps you could, instead of having multiple scripts each managing a cell, a Cell Object that can be duplicated and managed in a single script.

I ultimately don’t. It is what I wish to prevent because having 8 scripts + 8 remote events for each part (8 bricks in total) will definitely put strain on the game when there is a lot of players and things happening.

I would like to hear about your possible solution in more detail. Ultimately 1 script and 1 remote event for all the bricks is what I am aiming for but I have no clue as to how.