Tweening Problems

Extremely simple problem, but I somehow coudnt figure it out. Im a beginner scripter.
How come in this code

wait(2)
local Bezier = require(script:WaitForChild("Bezier"))
local TweenService = game:GetService("TweenService")

local Length = nil
local Speed = 30

local Tween = nil
local Goal = nil
--------------------- CURVE 1

local NewBezier1 = Bezier.new(workspace.P1, workspace.P2, workspace.P3)

Length = NewBezier1.Length

local TweenInformation = TweenInfo.new(Length/Speed, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
Tween = NewBezier1:CreateCFrameTween(script.Parent, {"CFrame"}, TweenInformation)
Tween:Play()

Tween.Completed:Wait()

--------------------- STRAIGHT 1

Length = (workspace.Y1.Position-workspace.Y2.Position).Magnitude

Goal = workspace.Y2.CFrame

TweenInformation = TweenInfo.new(Length/Speed, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
Tween = TweenService:Create(script.Parent, TweenInformation, Goal)
Tween:Play()


The first tween works fine, but the 2nd one, on line 31, it says unable to cast to dictionary.
Help is appreciated

2 Likes

Tweens expect, well, what your error said. It needs a dictionary where the key is the property you want to tween to.
Think of it this way:

{
    Property_name = target_value
}
  • Property_name: How is it going to know what to tween?
  • target_value: What should the target value be?

So, to fix your code, you can do this:

Tween = TweenService:Create(script.Parent, TweenInformation, {CFrame = Goal})

I think you should also look into the local keyword when defining variables.

1 Like

Thank you so much! And i will definitely look into defining variables. Thaank you

1 Like

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