Advertisement
Velinquish

Untitled

Apr 30th, 2020
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local TweenService = game:GetService("TweenService")
  2.  
  3. local tweenHinge = script.Parent.TweenHinge
  4. local swingHinge = script.Parent.SwingHinge
  5. local doorPart = script.Parent.Door
  6. local detectPushPart = script.Parent.DetectPush
  7. local detectPush
  8. local hinge = swingHinge.HingeConstraint
  9.  
  10. local tweenOpen = TweenInfo.new(2.95, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
  11. local tweenClose = TweenInfo.new(2.67, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
  12. local hingeCf = tweenHinge.CFrame
  13.  
  14. local isClosed = true
  15.  
  16. local function toggleOpen()
  17.     if isClosed == "In-progress" then return end
  18.     if isClosed then
  19.         isClosed = "In-progress"
  20.         -- Open sesame
  21.         hinge.Enabled = false
  22.         tweenHinge.Anchored = true -- Must anchor before tweening
  23.         local tween = TweenService:Create(tweenHinge, tweenOpen, {
  24.             CFrame = hingeCf * CFrame.Angles(0, math.rad(100), 0)
  25.         })
  26.         tween:Play()
  27.         tween.Completed:Wait()
  28.         hinge.Enabled = true -- Let it swing now
  29.         tweenHinge.Anchored = false
  30.         isClosed = false
  31.         detectPush = detectPushPart.Touched:Connect(function(hit)
  32.             if not hit == doorPart then return end
  33.             print("Door pushed closed")
  34.            
  35.             hinge.Enabled = false
  36.             tweenHinge.CFrame = hingeCf -- Just snaps it closed; easy-peasy
  37.             tweenHinge.Anchored = true -- Make sure it stays there and doesn't go flying off
  38.             isClosed = true
  39.             detectPush:Disconnect()
  40.         end)
  41.     else
  42.         isClosed = "In-progress"
  43.         if detectPush and detectPush.Connected then detectPush:Disconnect() end
  44.         hinge.Enabled = false
  45.         tweenHinge.Anchored = true
  46.         local tween = TweenService:Create(tweenHinge, tweenClose, {
  47.             CFrame = hingeCf
  48.         })
  49.         tween:Play()
  50.         tween.Completed:Wait()
  51.         isClosed = true
  52.     end
  53. end
  54.  
  55. script.Parent.Handle1.ClickDetector.MouseClick:Connect(toggleOpen)
  56. script.Parent.Handle2.ClickDetector.MouseClick:Connect(toggleOpen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement