Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- ------------------------------------------------------------------------------------------
- -- Services
- local TweenService = game:GetService('TweenService')
- ------------------------------------------------------------------------------------------
- -- Vars
- local openModel = script.Parent.doorOpen
- local closeModel = script.Parent.doorClosed
- local currentModel = script.Parent.doorCurrent
- local isOpen = true
- local duration = 6
- local tweensTable = {
- ["1"] = {},
- ["2"] = {},
- ["3"] = {},
- ["4"] = {},
- ["5"] = {}
- }
- ------------------------------------------------------------------------------------------
- -- Tween stuff
- local function onInfo(duration)
- -- When opening door
- return TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
- end
- local function offInfo(duration)
- -- When closing door
- return TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
- end
- --------------------------------------
- function module.Tween(on)
- if isOpen == nil or on == isOpen then return end
- local boolStorer = nil
- isOpen = nil
- if on == true then
- -- Will open
- for i = 1, 6 do
- if i > 2 then
- -- To top of vertical slider
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (i - 2) / 5), {CFrame = openModel.Model6.Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (i - 2) / 5), {CFrame = openModel.Model6.Gladds.CFrame})
- table.insert(tweensTable["1"], tween1)
- table.insert(tweensTable["1"], tween2)
- end
- if i > 1 and i < 6 then
- -- Going to tilt
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model5.Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model5.Gladds.CFrame})
- table.insert(tweensTable[tostring(i - 1)], tween1)
- table.insert(tweensTable[tostring(i - 1)], tween2)
- end
- if i < 5 then
- -- Going to Model4
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model4.Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model4.Gladds.CFrame})
- table.insert(tweensTable[tostring(i)], tween1)
- table.insert(tweensTable[tostring(i)], tween2)
- end
- if i < 4 then
- -- Going to its Open positions
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (4 - i) / 5), {CFrame = openModel["Model".. tostring(i)].Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (4 - i) / 5), {CFrame = openModel["Model".. tostring(i)].Gladds.CFrame})
- table.insert(tweensTable[tostring(i + 1)], tween1)
- table.insert(tweensTable[tostring(i + 1)], tween2)
- end
- boolStorer = true
- end
- elseif on == false then
- -- Will clsoe
- for i = 1, 6 do
- if i <= 3 then
- -- To Model4
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (4 - i) / 5), {CFrame = openModel.Model4.Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (4 - i) / 5), {CFrame = openModel.Model4.Gladds.CFrame})
- table.insert(tweensTable["1"], tween1)
- table.insert(tweensTable["1"], tween2)
- end
- if i < 5 then
- -- Tilt
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model5.Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model5.Gladds.CFrame})
- table.insert(tweensTable[tostring(5 - i)], tween1)
- table.insert(tweensTable[tostring(5 - i)], tween2)
- end
- if i < 6 and i > 1 then
- -- Tilt back
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model6.Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model6.Gladds.CFrame})
- table.insert(tweensTable[tostring(6 - i)], tween1)
- table.insert(tweensTable[tostring(6 - i)], tween2)
- end
- if i <= 6 and i > 2 then
- -- Go to its respective closed positions
- local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (i - 2) / 5), {CFrame = closeModel["Model".. tostring(i)].Frammmes.CFrame})
- local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (i - 2) / 5), {CFrame = closeModel["Model".. tostring(i)].Gladds.CFrame})
- table.insert(tweensTable[tostring(7 - i)], tween1)
- table.insert(tweensTable[tostring(7 - i)], tween2)
- end
- end
- boolStorer = false
- end
- for i = 1, 5 do
- for _, tweenThing in pairs(tweensTable[tostring(i)])do
- tweenThing:Play()
- end
- wait(duration / 5)
- end
- isOpen = boolStorer
- -- Emptying to prevent data leaks
- tweensTable = {
- ["1"] = {},
- ["2"] = {},
- ["3"] = {},
- ["4"] = {},
- ["5"] = {}
- }
- end
- ------------------------------------------------------------------------------------------
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement