In short, I was working on a sliding door a while ago. I couldn't for the life of me get the whole model (The door) to move using one script and so I had to tween each individual part and have them all connect to a single click detector. This meant (due to my lack of scripting knowledge most likely) that I had to write a script for every part and tween the parent. This totaled to 9 scripts per door. I know, awful. I was wondering if there was a more effective way of doing this using one script.
This is the script I inserted into each part.
opened = false
local TweenService = game:GetService("TweenService")
local part = script.Parent
local Info = TweenInfo.new(
2,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0
)
local open = {CFrame = part.CFrame + part.CFrame.lookVector * -4.2}
local close = {CFrame = part.CFrame }
local tweenOpen = TweenService:Create(part,Info,open)
local tweenClose = TweenService:Create(part,Info,close)
function toggle()
if opened == false
then tweenOpen:Play()
opened = true
else
tweenClose:Play()
opened = false
end
end
part.Parent.Paper.ClickDetector.MouseClick:connect(toggle)
Any help would be greatly appreciated! Thank you!

1 comment
It’s :Connect, not :connect (line 32)