Handling several spawn locations with one server script?

Currently I’m working on a project where I’m going to have items spawn in randomly copy pasted locations (lockers), But I’d like to avoid the optimization inefficiency of having a script inside of each location that handles itself, and instead one server-script-service script that handles all of them in workspace.

I know how to detect the locations and stuff, I’m just not sure how I would gather touch events from all of them & detect players pressing E on them inside of one script.

i cant really code the whole thing out for you but think of it this way. have a severscript in SSS and make a table for all of the spawn locations. then when its time for something to spawn make it so it chooses a random spawn from the table and a random item if the system works like that. to detect players pressing e and stuff on them have a prox prompt inside of each of the tools. then whenever any of the tools currently present in game is pressed e on check for which item it was, who the player was, give the player that tool to their backpack and then destroy the tool. there are many ways you can destroy them as well

So, I could do something like this:

WorkspaceTable = game.Workspace:GetDescendants()
LockerTable = {}

for i,v in pairs(WorkspaceTable) do
	if v.Name == "Test" then

But then how should I hook the LockerTable up to touch events?

well when it chooses the random item what you could do is make a variable for it and then make it so that when the proximity prompt is triggered it does its thing, at least thats how i would think of it, for the random item it chooses from said table

I’m going to be relying on remote events as I have a custom interaction system with Sensor bricks, the client communicates the sensor triggered to use and checks with magnitude but my main thing is how would I set the same script to detect events for all 50 or so of the spawn locations?

Are you using proximity prompts? You could tag all the prompts and use the tags to loop through them setting up the connections. I think the collectionservice was made for doing stuff like this.