Tween Service Door Shakes When Closing

When at a certian time of the day the door will open and at later in the day the door will close until the morning.

When the time of day hits 6pm the door is supossed to close but when it does it doesnt close completely and starts to shake back and forward but when opening it works fine.

local TweenService = game:GetService("TweenService") 

	local hinge = script.Parent.Hinge


	local goalOpen = {}
	goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(110), 0)

	local goalClose = {}
	goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)

	local tweenInfo = TweenInfo.new(1)
	local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
	local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)

local DoorOpened = false --Debounce

while true do
	wait(0.1)
	if game.Lighting:GetMinutesAfterMidnight() >= 6 * 60 and DoorOpened == false then
		tweenOpen:Play()
		DoorOpened = true
	end
	if game.Lighting:GetMinutesAfterMidnight() >= 18 * 60 and DoorOpened == true then
		tweenClose:Play()
		DoorOpened = false 
	end
end
External Media
4 Likes

It seems to me that the game is rapidly tweening it open and closed. This seems like a sign that the debounce is being released incorrectly.

This is probably because you’re not checking if it’s less then 18 at night in the door open part. See if this works.

while task.wait(0.1) do
	if game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime < 18 and DoorOpened == false then
		tweenOpen:Play()
		DoorOpened = true
	end
	if game.Lighting.ClockTime >= 18 and DoorOpened == true then
		tweenClose:Play()
		DoorOpened = false 
	end
end
2 Likes

Thank you this worked perfectly

1 Like

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