Why is code not working

local tweenService = game:GetService("TweenService")
local door = script.Parent.Base

local open = false

local openState = {}
openState.CFrame = door.CFrame * CFrame.Angles(0, math.rad(90), 0)

local closeState = {}
closeState.CFrame = door.CFrame * CFrame.Angles(0, 0, 0)

local tweeninfo = TweenInfo.new(1)
local openAnim = tweenService:Create(door, tweeninfo, openState)
local closeAnim = tweenService:Create(door, tweeninfo, closeState)

door.ClickDetector.MouseClick:Connect(function()
	if open == false then
		open = true
		openAnim:Play()
	else
		open = false
		closeAnim:Play()
	end
end)

Why is this not working?

2 Likes

I could be wrong, but maybe try this?

local TweenService = game:GetService(“TweenService”)
local door = script.Parent.Base

local open = false

– Define the open state by adjusting the Position of the door
local openState = {
CFrame = door.CFrame * CFrame.new(0, 0, -5)
}

– Define the close state as the initial position of the door
local closeState = {
CFrame = door.CFrame
}

local tweenInfo = TweenInfo.new(1)
local openAnim = TweenService:Create(door, tweenInfo, openState)
local closeAnim = TweenService:Create(door, tweenInfo, closeState)

door.ClickDetector.MouseClick:Connect(function()
if open == false then
open = true
openAnim:Play()
else
open = false
closeAnim:Play()
end
end)

2 Likes

image
It’s giving me this error for one of my tweens and also:

local tweenService = game:GetService("TweenService")
local door = script.Parent.Base

local openedPosition = script.Parent.OpenPosition
local closedPosition = script.Parent.ClosedPosition

local open = false

local openState = openedPosition.CFrame
local closeState = closedPosition.CFrame

local tweenInfo = TweenInfo.new(1)
local openAnim = tweenService:Create(door, tweenInfo, openState)
local closeAnim = tweenService:Create(door, tweenInfo, closeState)

door.ClickDetector.MouseClick:Connect(function()
	if open == false then
		open = true
		openAnim:Play()
	else
		open = false
		closeAnim:Play()
	end
end)

Would this code work?

1 Like

try this

local tweenService = game:GetService("TweenService")
local door = script.Parent.Base

local open = false

local tweeninfo = TweenInfo.new(1)
local openAnim = tweenService:Create(door, tweeninfo, {CFrame = door.CFrame * CFrame.Angles(0, math.rad(90), 0)})
local closeAnim = tweenService:Create(door, tweeninfo, {CFrame = door.CFrame * CFrame.Angles(0, 0, 0)})

door.ClickDetector.MouseClick:Connect(function()
	if open == false then
		open = true
		openAnim:Play()
	else
		open = false
		closeAnim:Play()
	end
end)
1 Like

you need to add curly brackets

local openAnim = tweenService:Create(door, tweenInfo, {CFrame = openState})
local closeAnim = tweenService:Create(door, tweenInfo, {CFrame = closeState})
1 Like

The third parameter of TweenService:Create expects a dictionary argument.

Yeah it opens with this now. However it opens in the middle of the doorframe and not on the side of it. I’ve tried adding a hingeconstraint or a weld but neither seem to work.