Hi so as the title say i need help with making a garage door, I have the frame and such built but i am newer to scripting and using constraints, I am trying to make a realistic garage door for a game i am starting to develop. I have tried using the AI assistant but its all so confusing to me
This script will use a HingeConstraint to simulate the opening and closing of the door. Assuming you already have the door structure and the door itself, the script will be responsible for rotating the door around an axis.
-- We have the door here.
local door = script.Parent
local open = false
openAngle location = 90
local closedAngle = 0
local speed = 2
--Opens and closes.
local function toggleDoor()
if open then
for i = openAngle, closedAngle, -speed do
door.HingeConstraint.TargetAngle = i
wait(0.01)
end
else
for i = closedAngle, openAngle, speed do
door.HingeConstraint.TargetAngle = i
wait(0.01)
end
end
open = not open
end
-- Click and watch the magic happen.
door.ClickDetector.MouseClick:Connect(toggleDoor)
garage door script. First up, the HingeConstraint. Make sure it’s aligned just right with the axis.
Next, the script. Just pop it inside the door part. And don’t forget the ClickDetector. Want that door to swing open with a click? This little guy makes it happen. Without it, nothing moves.
Tweak the openAngle and speed. Fast or slow? It’s your call.
local TweenService = game:GetService("TweenService")
-- We have the door here.
local OPEN_ANGLE = 90
local CLOSED_ANGLE = 0
local LENGTH = 2
local door = script.Parent
local open = false
--Opens and closes
local tweenInfo = TweenInfo.new(LENGTH, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local debounce = false
local function ToggleDoor()
if debounce then return end
debounce = true
if open then
openTween:Play()
openTween.Completed:Wait()
debounce = false
else
closeTween:Play()
closeTween.Completed:Wait()
debounce = false
end
open = not open
end
-- Click and watch the magic happen.
door.ClickDetector.MouseClick:Connect(toggleDoor)
(Also if you want one of those garages where the slits move along a track then you’re probably going to have to use pathfinding or something.)