Hi guys, I’m trying to make a door that opens on the click of a button, but it doesn’t work. When I try to tween it, it says “Unable to cast to Dictionary” on line 21.
local ts = game:GetService("TweenService")
local cd = script.Parent.ClickDetector
local db = false
local open = script.Parent.Parent.Parent.Opened.Value
local info = TweenInfo.new(
0.75,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
cd.MouseClick:Connect(function()
if db == false then
db = true
if open == false then
open = true
local door = script.Parent.Parent.Parent.Door
local opentween = ts:Create(door, info, {door.CFrame = (door.CFrame + Vector3.new(0,6,0))})--ERROR LINE
opentween:Play()
opentween.Completed:Connect(function()
db = false
end)
elseif open == true then
open = false
local door = script.Parent.Parent.Parent.Door
local closetween = ts:Create(door, info, {door.CFrame = (door.CFrame + Vector3.new(0,-6,0))})
closetween:Play()
closetween.Completed:Connect(function()
db = false
end)
end
end
end)
There are two CloseDoors because there are two buttons on either side of the door which let you open it, both using “Opened” BoolValue to determine if the door is opened or not.
It looks like the issue is with the syntax of the third argument to the Create method of the TweenService object. The third argument should be a table that specifies the properties of the object that you want to animate and their target values.
In this case, you are trying to animate the CFrame property of the door object, so the table should contain a single key-value pair with the key being “CFrame” and the value being the target value for the property.
However, the current code is trying to set the value of the door.CFrame property using an assignment operator (=), which is not allowed. Instead, you should use the colon equal operator (:) to specify the target value for the property.
Here’s how the line should be corrected:
local opentween = ts:Create(door, info, {CFrame = door.CFrame + Vector3.new(0,6,0)})
This will create a Tween that animates the CFrame property of the door object from its current value to a new value that is offset by (0,6,0) along the Y-axis.