Alright so this is ran through two GUI buttons and a RemoteEvent. It works perfectly fine. My main issue is I feel like there's an easier way to do this.
What the script is suppose to do.
The script checks to see if SteelCage is a model in workspace and if it is then it continues the code. if the function Open is ran, it turns all of door1's parts transparency to 1 and turns off CanCollide then turns all of door2's parts transparency to 0 and turns on CanCollide. elseif the function is Closed, it turns the door1 parts transparency to 0 and turns on CanCollide then turns all of door2s parts transparency to 1 and CanCollide off. | Yes, the variables named door1 and door2 have to be inside the code script sadly so it doesn't break the entire script as I move this item from ServerStorage to Workspace.
My Question.
Is there a way to make this easier or look more clean? Maybe even move it down a button?
--Made By MillerrIAm
------------------Variables----------------
Event = game.ReplicatedStorage.ExtraEvents.CageDoorEvent
------------------Main Script------------------
Event.OnServerEvent:Connect(function(Player,Door)
if game.Workspace:FindFirstChild("SteelCage") then
if Door == "Open" then
local door1 = game.Workspace.SteelCage.Doors.CageDoor1:GetChildren()
local door2 = game.Workspace.SteelCage.Doors.CageDoor2:GetChildren()
for i, x in pairs(door1) do
x.Transparency = 1
x.CanCollide = false
end
for i, v in pairs(door2) do
v.Transparency = 0
v.CanCollide = true
end
elseif Door == "Close" then
local door1 = game.Workspace.SteelCage.Doors.CageDoor1:GetChildren()
local door2 = game.Workspace.SteelCage.Doors.CageDoor2:GetChildren()
for i, x in pairs(door1) do
x.Transparency = 0
x.CanCollide = true
end
for i, v in pairs(door2) do
v.Transparency = 1
v.CanCollide = false
end
end
else
end
end)
--[[if Door == "Open" then
Get all of the children of CageDoor1 & CageDoor2
Turn all of Door1's parts Transparency to 1 and turn CanCollide off
then turn all of Door2's parts Transparency to 0 and cancollide on.
elseif Door == "Close" then
Get all of the children of CageDoor1 & CageDoor2
Turn all of Door2's parts Transparency to 1 and turn CanCollide off
then turn all of Door1's parts Transparency to 0 and cancollide on.]]

3 comments
I know the script is a mess, I apologize. I just want to know exactly what I can do. If I can do multiple values for the in pairs (values) then please inform me on a way I can learn how to do this please.
I've been looking and attempting for a while and nothings working.
FYI again, This script DOES work so I know it's possible.