I'm having trouble trying to wrap my mind around the best way to have a single script that's able to detect and interact with multiple different clickdetectors/touched parts at once.
For example, if I wanted to make multiple doors that had clickdetectors inside them and then have a single script that allowed me to open and close all these doors as freely as I wanted to, with as many doors as I wanted to, how would I go about it?
I tried this with a for loop that obtained all the parts with clickdetctors, but the problem is that they cannot act independently from each other, and the script would break if you attempted to open any other door. I'm not even sure if this is the most efficient method of going about it, but having multiple scripts that all basically do the same thing doesn't seem right to me.
Is it possible to do all this in a single script with maybe one or two functions?
At its base, this is all the code is:
click = script.Parent.ClickDetector
click.MouseClick:Connect(function()
local door = click.Parent
if door.Transparency == 0 and door.CanCollide == true then
door.Transparency = 1
door.CanCollide = false
else
door.Transparency = 0
door.CanCollide = true
end
end)
Any way to make multiple of these scripts into a single script?

1 comment
This method works, but my only issue is if I wanted to add more doors, I would always have to keep adding more variables. I'd like to pair it with a for loop that gets the parts I'm looking for, which I'm aware complicates things. Apologies for the somewhat unclear question.