Hello, I’m making a sentry and I don’t know how to animate it, so I was planning to use tweens. I was also told to tween the CFrame instead of position.
Code (i plan to clean it later…):
-- Properties
local defCFrame = script.Parent.Top.Main.CFrame
local newCFrame = CFrame.new(-16.549163818359, 2.2986037731171, -14.178249359131)
-- Services
local TweenService = game:GetService("TweenService")
-- Tweens
local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad), CFrame == defCFrame)
-- Code
local function Build()
script.Parent.Top.Main.CFrame = newCFrame
SentryBuildTween:Play()
end
-- temporary
wait(5)
Build()
The sentry goes into the “newCFrame” pose, then errors with Unable to cast to Dictionary. Any obvious mistakes?
You might want to fill in all the ‘tweeninfo’ parameters. The third parameter is supposed to be a dictionary which can contain many different options. Try this:
{
["CFrame"] = defCFrame
}
-- as the third parameter for tweenservice:Create(), instead of ''CFrame == defCFrame'
Can you paste the new code replacing local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1, Enum.EasingStyle.Quad), CFrame == defCFrame)
Try replacing the line with local SentryBuildTween = TweenService:Create(script.Parent.Top.Main, TweenInfo.new(1,Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0), {["CFrame"]=defCFrame})
You didn’t fill in the full TweenInfo parameters (Which I think is fine… unsure), and you have to let the 3rd parameter be a dictionary, even if you are only tweening 1 property. Example:
{
["Position"] = Vector3.new(0,0,0),
["Size"] = Vector3.new(10,10,10)
}
--[[ You could tween 2 properties at once. Even if you don't need to do so,
you have to format it as a dictionary (Brackets): ]]--
{
["Position"] = Vector3.new(0,0,0)
}
You made a mistake on the 3rd argument with CFrame == defCFrame. This will check if they are equal and return a boolean causing the cast error. Instead use {CFrame = defCFrame} since TweenService:Create takes a table of properties to tween.