Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Astralyst 389 Moderation Voter
5 years ago

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

Log in to vote
1
Answered by
theCJarmy7 1293 Moderation Voter
5 years ago
Edited 5 years ago

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
0
i guess that works too, but solved my problem using modulescripts. thanks anyways! Astralyst 389 — 5y
Ad

Answer this question