Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error while trying to tween: Unable to cast to Dictionary?

Im trying to make a gun's barrel move back while shooting, but im stuck here.

local goal = {weapon.BarrelRecoil.Position}
local twinfo = TweenInfo.new(5)
local tw = game.TweenService:Create(weapon.Barrel, twinfo, goal)
tw:Play()

Its a LocalScript, can that be a problem? I dont really know tweening, i dont use it too much. The console writes out Unable to cast to Dictionary.

2 comments

0

try do FindFirstChild("BarrelRecoil") and FindFirstChild("weapon") before making a dictionary

0

Its already in the script

3 answers

✓ Accepted answer

The problem is that you're not defining what property of the tween will be changed, you're only giving it a Vector3 value without any definitions.

To fix this, do something like this:

local goal = {Position = weapon.BarrelRecoil.Position} -- Defined position
local twinfo = TweenInfo.new(5)
local tw = game.TweenService:Create(weapon.Barrel, twinfo, goal)
tw:Play()

You can even have other properties change. Like CFrame, Color and much more.

1 comment

0

Thanks

well the thing is TweenInfo.new doesn't take a number, instead it takes arguments that dictate how the tween will play.. such as time, style, direction, etc.. learn more here about the arguments that TweenInfo.new takes... TweenInfo.new can also be called without any arguments, which will result in the default tween properties being applied..

2 comments

0

So how do i set the duration/speed of the tween?

0

the first argument to TweenInfo.new() is the duration of the tween..

Tween takes the property justified only, use this:

local goal = {}
goal.Position = weapon.BarrelRecoil.Position

local twinfo = TweenInfo.new(5)
local tw = game.TweenService:Create(weapon.Barrel, twinfo, goal)
tw:Play()

This discussion is preserved as it was. New answers, comments, and votes are closed.