Cant cast to dictionary tween error

I can’t fix the unable to cast to dictionary error, and I was wondering how do you put the positions in a table and make the tween work instead of just putting them in variables. Im trying to make a tornado move around in different directions every few seconds. I’m open for any suggestions how to improve my code and also mabye someone can tell me how can i make the tornado move to random directions in a set radius or boundaries?

local Tornado = script.Parent
local folder = Tornado.Parent
local TweenService = game:GetService("TweenService")

local Positions = {folder.Pos1,folder.Pos2,folder.Pos3,folder.Pos4,folder.Pos5,folder.Pos6,folder.Pos7,folder.Pos8}

local tweenInfo = TweenInfo.new(
	math.random(6,12),
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
	)

while task.wait() do
	local part = math.random(1,8)
	local position = Positions[part].Position
	local waitTime = math.random(6,12)
	local tweenInfo = TweenInfo.new(
		waitTime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	
	local tween = TweenService:Create(Tornado,tweenInfo,position)
	tween:Play()
	task.wait(waitTime)
	
end
2 Likes
local Tornado = script.Parent
local folder = Tornado.Parent
local TweenService = game:GetService("TweenService")

local Positions = {folder.Pos1,folder.Pos2,folder.Pos3,folder.Pos4,folder.Pos5,folder.Pos6,folder.Pos7,folder.Pos8}

local tweenInfo = TweenInfo.new(
	math.random(6,12),
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
	)

while task.wait() do
	local part = math.random(1,8)
	local position = {Position : Positions[part].Position}
	local waitTime = math.random(6,12)
	local tweenInfo = TweenInfo.new(
		waitTime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	
	local tween = TweenService:Create(Tornado,tweenInfo,position)
	tween:Play()
	task.wait(waitTime)
	
end

Above is fixed code, you need to pass tween arguments like this
{Property : Value}

You must give an table with tween goals as third argument:

TweenService:Create(Instance, TweenInfo, PropertiesGoals)

This table (dictionary) must have all properties that should be tweened with their final goals set as values.
For example:

{
    Position = Vector3.new(0,0,0),
    Transparency = 1
}

Fixing your problem;

local tween = TweenService:Create(Tornado, tweenInfo, {
     Position = (vector3 here),
})

tween:Play()

Be aware that most properties can’t be tweened (mostly the ones that are either strings or booleans) and that there’s some you can tween, but should not. As in the case of UIStroke’s Thickness property when applied to a TextLabel because of severe perfomance impact.

More informations:

1 Like

I changed it to this, now i get no error but nothing happens.

local Tornado = script.Parent
local folder = Tornado.Parent
local TweenService = game:GetService("TweenService")

local Positions = {folder.Pos1,folder.Pos2,folder.Pos3,folder.Pos4,folder.Pos5,folder.Pos6,folder.Pos7,folder.Pos8}

local tweenInfo = TweenInfo.new(
	math.random(6,12),
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
	)

while task.wait() do
	local part = math.random(1,8)
	local position = Positions[part].Position
	local waitTime = math.random(6,12)
	local tweenInfo = TweenInfo.new(
		waitTime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	
	local tween = TweenService:Create(Tornado,tweenInfo,{Position = position})
	task.wait(waitTime)
	
end

looks like you forgot to call :Play() on the tween

You didn’t call :Play() on the tween.

lol thank you, works perfectly now

You may use tween.Completed:Wait() instead. This will be more accurate.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.