Unable to cast to Dictionary while doing a tween

Hi!

Somehow I messed up a simple tween, this is the line.

	game:GetService("TweenService"):Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Camera.CFrame == player.Character.Head.CFrame}):Play()

The error is this
image

Thanks for any help!

1 Like

For tweens, you don’t need to specify Camera.CFrame in the tween list (the {Camera.CFrame == player.Character.Head.CFrame} thing). Change it to CFrame instead

Also, == is for comparisons, = is for modifying. Use = for modifying dictionary items

In the end, we have this:

game:GetService("TweenService"):Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {CFrame = player.Character.Head.CFrame}):Play()

all i’m going to say is i’m a huge idiot. thanks :slight_smile:

This will need to be [CFrame] otherwise the script will confuse the reference to CFrame as a class reference as opposed to a key/field of the goals table (property) of the tweened instance.

No, it doesn’t. Entries in dictionaries with no surrounding square brackets are automatically interpreted as strings.

Proof:

local Table = {
	CFrame = true
}

for i,v in pairs(Table) do
	print(typeof(i))
end

Using [CFrame] actually has the opposite effect, breaking it:

local Table = {
	[CFrame] = CFrame.new(1,4,6)
}

game:GetService("TweenService"):Create(workspace.SpawnLocation,TweenInfo.new(1),Table):Play()

TweenService uses strings to figure out which properties to tween, so when it tries to convert the table to a string and find the property, the Part doesn’t have a property named <Table> (table: 0xa8d33f552f40617c)

I’m aware of this convention, this might have been recently changed with Luau, I’m trying to find some of my earlier posts where users where having issues for attempting to tween the “CFrame” property of an instance without wrapping the property name inside a pair of square braces.

I don’t think this has been changed recently. I’ve been using this for over a year now, and it worked then as well as it does now.

Perhaps I’m misremembering, these posts were made quite some time back (1-2 years+), at the very least they silence the purple class-name marker which appears (aesthetic preference).

You’ve probably mistaken that for something else, it still shows up:


image

If we want to continue this discussion, we should probably move to DMs.