Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TweenService = game:GetService("TweenService")
- local tweenHinge = script.Parent.TweenHinge
- local swingHinge = script.Parent.SwingHinge
- local doorPart = script.Parent.Door
- local detectPushPart = script.Parent.DetectPush
- local detectPush
- local hinge = swingHinge.HingeConstraint
- local tweenOpen = TweenInfo.new(2.95, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
- local tweenClose = TweenInfo.new(2.67, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
- local hingeCf = tweenHinge.CFrame
- local isClosed = true
- local function toggleOpen()
- if isClosed == "In-progress" then return end
- if isClosed then
- isClosed = "In-progress"
- -- Open sesame
- hinge.Enabled = false
- tweenHinge.Anchored = true -- Must anchor before tweening
- local tween = TweenService:Create(tweenHinge, tweenOpen, {
- CFrame = hingeCf * CFrame.Angles(0, math.rad(100), 0)
- })
- tween:Play()
- tween.Completed:Wait()
- hinge.Enabled = true -- Let it swing now
- tweenHinge.Anchored = false
- isClosed = false
- detectPush = detectPushPart.Touched:Connect(function(hit)
- if not hit == doorPart then return end
- print("Door pushed closed")
- hinge.Enabled = false
- tweenHinge.CFrame = hingeCf -- Just snaps it closed; easy-peasy
- tweenHinge.Anchored = true -- Make sure it stays there and doesn't go flying off
- isClosed = true
- detectPush:Disconnect()
- end)
- else
- isClosed = "In-progress"
- if detectPush and detectPush.Connected then detectPush:Disconnect() end
- hinge.Enabled = false
- tweenHinge.Anchored = true
- local tween = TweenService:Create(tweenHinge, tweenClose, {
- CFrame = hingeCf
- })
- tween:Play()
- tween.Completed:Wait()
- isClosed = true
- end
- end
- script.Parent.Handle1.ClickDetector.MouseClick:Connect(toggleOpen)
- script.Parent.Handle2.ClickDetector.MouseClick:Connect(toggleOpen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement