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
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}
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.
UIStroke
“Be mindful of tweening the Thickness property of a UIStroke applied to text objects. This renders and stores many glyph sizes each frame, potentially causing performance issues or text flickering.” UIStroke | Documentation - Roblox Creator Hub
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