"Unable to cast to Dictionary" even though the tween code seems right

Hello, I’m making a sentry and I don’t know how to animate it, so I was planning to use tweens. I was also told to tween the CFrame instead of position.

Code (i plan to clean it later…):

-- Properties

local defCFrame = script.Parent.Top.Main.CFrame
local newCFrame = CFrame.new(-16.549163818359, 2.2986037731171, -14.178249359131)

-- Services

local TweenService = game:GetService("TweenService")

-- Tweens

local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad), CFrame == defCFrame)

-- Code

local function Build()
	script.Parent.Top.Main.CFrame = newCFrame
	SentryBuildTween:Play()
end

-- temporary

wait(5)
Build()

The sentry goes into the “newCFrame” pose, then errors with Unable to cast to Dictionary. Any obvious mistakes?

1 Like

You might want to fill in all the ‘tweeninfo’ parameters. The third parameter is supposed to be a dictionary which can contain many different options. Try this:

{
["CFrame"] = defCFrame
}
-- as the third parameter for tweenservice:Create(), instead of  ''CFrame == defCFrame'

Still errors except nothing else happens.

Maybe because of the brackets between

TweenInfo.new(1, Enum.EasingStyle.Quad)

Try getting rid of them.

TweenInfo.new(1), Enum.EasingStyle.Quad, CFrame = defCFrame))

Reply if this helped.

Also making variables would make it easier.

Can you paste the new code replacing
local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad), CFrame == defCFrame)

TweenInfo.new( Seconds, Style, Direction, Repeat, TweenBack, Delay No, you don’t put that statement in TweenInfo

local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad), "CFrame" == defCFrame)

The brackets made it error, so I removed them

This doesn’t make any sense?

And I made variables?

Nono, put it in a dictionary…

local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0), {
["CFrame"] = defCFrame
})

You need brackets around the properties. You also have == instead of =.

you don’t use a string, you just set the property name.

local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad), {CFrame = defCFrame})

If I put only one =, it also errors out, kinda like if thens or something.

I am so confused rn

You should try putting Easing Style at the end of the tween.

local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1), {CFrame = defCFrame}, Enum.EasingStyle.Quad)

Try this.

Sorry, typo for the ==. The bracket & name works fine, and it’s been the way I’ve tweened everything.

1 Like

Try replacing the line with
local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1,Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0), {["CFrame"]=defCFrame})

1 Like

Seems like that did it, thanks.
What did I mess up though? I’m still really confused lol

You didn’t fill in the full TweenInfo parameters (Which I think is fine… unsure), and you have to let the 3rd parameter be a dictionary, even if you are only tweening 1 property. Example:

{
["Position"] = Vector3.new(0,0,0),
["Size"] = Vector3.new(10,10,10)
}
--[[ You could tween 2 properties at once. Even if you don't need to do so,
you have to format it as a dictionary (Brackets): ]]--
{
["Position"] = Vector3.new(0,0,0)
}
2 Likes

You made a mistake on the 3rd argument with CFrame == defCFrame. This will check if they are equal and return a boolean causing the cast error. Instead use {CFrame = defCFrame} since TweenService:Create takes a table of properties to tween.