Unable to cast Dictionary to TweenInfo in output when trying to move a part

  1. What do you want to achieve? I want to create a simple TweenService that moves a part from one position to another and then back to its origin again and again.

  2. What is the issue? Whenever I run the game/play it says “Unable to cast Dictionary to TweenInfo” .

  3. What solutions have you tried so far? I’ve looked everywhere and nothing works sadly.

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

local tweeninfo = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	-1,
	true,
	0

)


local endgoal = {}
endgoal.Position = Vector3.new(742.352, -8.475, -209.952)

local tween = tweenService:Create(part, TweenInfo, {Position = endgoal})

tween:Play()

Looks like you commenced a table-ception incident :thinking:

Try this:

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

local tweeninfo = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	-1,
	true,
	0

)


local endgoal = {
    Position = Vector3.new(742.352, -8.475, -209.952)
}

local tween = tweenService:Create(part, TweenInfo, {Position = endgoal.Position})

tween:Play()
2 Likes

just Fixed it and same error… “Unable to cast Dictionary to TweenInfo”

Oh I just noticed the other mistake

Since Lua is case-sensitive, you have to reference the second parameter TweenInfo as your variable instead (Or tweeninfo)

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

local tweeninfo = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	-1,
	true,
	0

)


local endgoal = {
    Position = Vector3.new(742.352, -8.475, -209.952)
}

local tween = tweenService:Create(part, tweeninfo, {Position = endgoal.Position})

tween:Play()

You actually went ahead & referenced the constructor for the TweenInfo.new(), but not your own custom variable which is tweeninfo

3 Likes

yea jack is right, you were setting position = to a table/dictionary

instead what you shouldve done is

local endgoal = {Position = Vector3.new(742.352, -8.475, -209.952)}

--later in tween create
local tween = tweenService:Create(part, TweenInfo, endgoal )

would be a way to do it

and yea you also mistyped the info

1 Like

Oh, Thanks so much it works now :grinning_face_with_smiling_eyes: silly me