Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you prevent duplicate scripts by only using one script for the whole thing?

Question says it all, I'm trying to figure out a way;

Basically, I have a door. These doors are all duplicates, they're all the same. However, I don't want to just clone the script to each and every one of them.

Is there a way to use only ONE script for the whole thing?

1 answer

✓ Accepted answer

You could loop over all the doors.

local doorList = {
	game.Workspace.Dor,
	game.Workspace.Dore,
}

for i, door in pairs(doorList) do
	--Do a door thing
end

If you don't want to manually put all the doors in the table, you could put them all in autimatically at the start of the game.

local doorList = {}


for i, inst in pairs(game.Workspace:GetDescendants()) do
	if isADoor(inst) then
		--add it to the door list
	end
end

1 comment

0

i guess that works too, but solved my problem using modulescripts. thanks anyways!

This discussion is preserved as it was. New answers, comments, and votes are closed.