Door not opening when clicking for the first time?

Hello folks. I am trying to make a garage door for my game, however, whenever I join the game and click to open it for the first time, it does not open. The noise plays as if it were opening, however, the door does not move. After this first click though, the door will open and close like normal. Can someone help me fix this issue?

Here is the script used to make it open/close:

local ClickDetector = script.Parent.ClickDetector
local closePos = script.Parent.Parent.DoorClose
local Door = script.Parent
local openPos = Door.CFrame * CFrame.Angles(0,0,0)
local closed = true
local doorTime = 4.5
local Sound = script.Parent.Sound
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(doorTime,Enum.EasingStyle.Linear,Enum.EasingDirection.Out, 0, false, 0 )

ClickDetector.MouseClick:Connect(function() 
	if closed then
		tweenService:Create(Door,tweenInfo,{CFrame = openPos}):Play()
		Sound:Play()
		closed = false	
	else 
		tweenService:Create(Door,tweenInfo,{CFrame = closePos.CFrame}):Play()
		Sound:Play()
		closed = true	
	end
end)

image

Here is a video demo of the issue.

anything showing up in your output?

1 Like

So, it seems like the issue with the garage door not opening on the first click is that it’s not starting in the correct position. To fix this, we need to add a line of code that sets the door to its initial position before the “if closed then…else…” loop in the “ClickDetector.MouseClick” event.

Check this code with the added line:

local ClickDetector = script.Parent.ClickDetector
local closePos = script.Parent.Parent.DoorClose
local Door = script.Parent
local openPos = Door.CFrame * CFrame.Angles(0,0,0)
local closed = true
local doorTime = 4.5
local Sound = script.Parent.Sound
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(doorTime,Enum.EasingStyle.Linear,Enum.EasingDirection.Out, 0, false, 0 )

ClickDetector.MouseClick:Connect(function() 
    Door.CFrame = closePos.CFrame -- Add this line to set the door to its initial position
	if closed then
		tweenService:Create(Door,tweenInfo,{CFrame = openPos}):Play()
		Sound:Play()
		closed = false	
	else 
		tweenService:Create(Door,tweenInfo,{CFrame = closePos.CFrame}):Play()
		Sound:Play()
		closed = true	
	end
end)

1 Like

Hey so I tried what you said and this was the result…


Not too sure what to do.

oh sorry i think it will works

1 Like

I’ve been checking the output and there is nothing. :frowning:

or maybe just try using the three first arguements of TweenInfo

simply reverse the tween positions between close and open

1 Like

I did what you said and it worked! Thanks! I can’t believe I didn’t think to do this beforehand. I switched the positions in the script and now the door opens on the first click. :smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.