Problems with Tweening A Start and a end Speed, Keep getting error Unable to cast to dictionary

This is what i have so far.

local StartSpeed = 150
local EndSpeed = 0

local TweenService = game:GetService("TweenService")

local TweeningInfo = TweenInfo.new(
    3,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.InOut,
    0,
    false,
    0
)

local Tween = TweenService:Create(StartSpeed, TweeningInfo, EndSpeed)

Tween:Play()

unable

The first parameter must be an Instance and the last parameter must be a dictionary.

propertyTable (the last argument required in TweenService:Create) requires a dictionary supplied to it that describes the Instances’ properties AFTER tweening, in this case, this wouldn’t work since you can only tween Instances.
I believe you would have to use an object value (IntValue, NumberValue) to achieve what you want. How it could potentially look like:

local TweenService = game:GetService("TweenService")
local ObjectValue = script...

local StartSpeed = 150
local EndSpeed = 0

ObjectValue.Value = StartSpeed

local TweeningInfo = TweenInfo.new(
    3,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.InOut,
    0,
    false,
    0
),

Properties = {
    Value = EndSpeed
}

local Tween = TweenService:Create(ObjectValue, TweeningInfo, Properties)
Tween:Play()
1 Like

What would

ObjectValue = script...

be?

The path to wherever that Object Value would be for example in workspace or under a player

1 Like

So im Confused now (the script i was making was originally for a jetpack) so when i press a key like w I would Go the start speed But then slow down after im done pressing the key. Would i put a objectvalue in the script itself?

That could work yes, you could keep an object value under the script or wherever you want to, it will still work the same way

1 Like

The first parameter in TweenService:Create() is the thing your tweening (instance). The second is the info, you got that. And the third is a dictionary or table of what your trying to change for example, it you want to tween a part’s Size.

local TS = game:GetService("TweenService")
local part = game.Workspace.Part

local TI = TweenInfo.new(
3, 
Enum.EasingStyle.Liner,
Enum.EasingDirection.Out,
0,
false,
0
)

local goal = {
Size = Vector3.new(5,5,5);
}

local tween = TS:Create(part, TI, goal)
tween:Play()
1 Like

im getting the error

invalid argument #3 (Instance expected, got number)

Yes because your variable is a number, not an instance.

1 Like

I explain the parameters above in my comment.

1 Like

How would i make it so i dont have to use a instance? Like a part

I don’t think you can, unfortunately.

1 Like

Because im just wanting the Speed of it to go down from 150 to 0, then when i press a key it goes the same way

If you want to make it so your jetpack gradually increases its speed, you could try multiplying the current speed of it by a decimal when you press “W” or which ever key.

When I say decimal I mean 1.2 or 1.6. for example.
Not 0.4 or 0.5 for example.

How would i do that?? Can i have an example?

You could multiply it by zero point something if you want the speed to decrease and multiply it by one point something to increase

for example:

speed*1.3 -- to increase

speed*0.8 -- to decrease
1 Like

Would i do this?

local Speed = 150

Speed*0.8

Sure. Then it would subtract 20% of the current speed. Thus the speed would decrease. Yes.

Just use a for loop or a while loop, Tween Service is for creating animations for instances, not for increasing nor decreasing a number.

1 Like