Is my function safe from coincidental multiple use?

I’m making a script in serverscriptstorage, shared by all players due to its complexity, where a table is updated in a loop, and once the loop finishes i add to the table. this is my code.

local function ConnectionMaker(connections, wire, empty)
	if empty == false then
		local currentlyinatable = false
		local CircuitData,i = {},0
		for key1,ConnectionWireModel in pairs(connections) do
			for key2, circuitv in pairs(CircuitGroups) do
				for key3, wirev in pairs(circuitv["Wires"]) do
					if ConnectionWireModel.Parent == wirev then
						i += 1
						CircuitData[i] = {circuitv["Wires"],ConnectionWireModel.Parent}

		for i  = 1,#CircuitData do
			print("OMG! WIRE CONNECTED!")
		table.insert(CircuitGroups,{ --this creates an new table
			["Wires"] = {wire},
			["Components"] = {}
		print("no connections found, new circuit made!")

the problem is, i have a sneaking suspicion that, should two people coincidentally use this function at the same time, the CircuitData table will be shared between those two people and this would be a big problem for me.

am i wrong to believe this? or if im right is there a way i can make the table unique to each time the function is called?

As long as you don’t have any yielding within your ConnectionMaker function, it would be impossible for that function to be called in two separate environments “at the same time”. However, even if it was used at the same time, your CurcuitData table is already local to the ConnectionMaker function, so it would not be shared between function calls. The CircuitGroups, however, will be shared since it is declared outside ConnectionMaker.

1 Like

Thanks! i just wanted a second opinion on it cuz im decently new to scripting. and on the CircuitGroups table, those ones are fine, they need to be global & shared.