Garage Door Thingy


I made a door similar to the garage door thingy from Security Breach and I want to know if I can improve this.

local TS = game:GetService "TweenService"

local Gateway = script.Parent

local Door = Gateway.Door
local Hitbox = Gateway.Hitbox

local Opening = Gateway.Opening
local Closed = Gateway.Closed

local Top = Gateway.Top
local Bottom = Gateway.Bottom

local TopTween = TS:Create(Door, TweenInfo.new (1.2, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Position = Top.Position})
local BottomTween = TS:Create(Door, TweenInfo.new (1.2, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Position = Bottom.Position})

local O
local C

Hitbox.Touched:Connect(function(Object)
	if Object.Name == "HumanoidRootPart" then
		O = true
		C = false
		
		local TwitchTween = TS:Create(Door, TweenInfo.new (.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.In), {Position = Vector3.new (Door.Position.X, Door.Position.Y + 2, Door.Position.Z)})
		TwitchTween:Play()

		Opening:Play()
		
		task.wait (.7)
		
		TopTween:Play()
		
		task.wait (1.2)
		if C then return end
		
		Opening:Stop()
		Closed:Play()
	end
end)

Hitbox.TouchEnded:Connect(function(Object)
	if Object.Name == "HumanoidRootPart" then
		O = false
		C = true
		
		local TwitchTween = TS:Create(Door, TweenInfo.new (.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.In), {Position = Vector3.new (Door.Position.X, Door.Position.Y - 2, Door.Position.Z)})
		TwitchTween:Play()
		
		Opening:Play()

		task.wait (.7)

		BottomTween:Play()
		
		task.wait (1.2)
		if O then return end
		
		Opening:Stop()
		Closed:Play()
	end
end)
2 Likes

As a fan of Fnaf Security Breach this is just amazing keep the good work up.

1 Like

That’s great, but to avoid bugs, I think is better use Magnitude instead of Touched Event (and use Magnitude in HitBox Part)

1 Like

Instead of using waits you can do

YourTween.Completed:Wait()

This will wait until the tween has finished.

Same with sounds.

YourSound.Ended:Wait()

The tween completed fires when a tween is finished or canceled, so that wouldn’t be ideal since the tween going up is canceled when a player leaves the designated area.

How should I achieve this effect?

1 Like