Hey everyone! So this keeps happening to me when I make a tween, not all the time, but sometimes. whenever I write a script, and play the tween, it always says “Unable to cast to Dictionary” I have looked in the object browser and I’ve been trying to figure it out but I can’t seem to figure it out. Here is my script, the error happens when I make the properties.
local TweenService = game:GetService("TweenService")
local part = script.Parent
local info = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)
local properties = {part.CFrame * CFrame.Angles(math.rad(75), math.rad(180), math.rad(-90))}
local prop = {part.CFrame * CFrame.Angles(math.rad(75), math.rad(0), math.rad(90))}
local tween = TweenService:Create(part,info,properties)
local Tween = TweenService:Create(part,info,prop)
while true do
tween:Play()
wait(3)
Tween:play()
wait()
end
If anyone can help me for the future, that would be great :)))
It’s because you never actually cast to the CFrame inside of the properties dictionary, all you do is tell the code about a CFrame value.
Revised Code:
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local part = script.Parent
local tween1, tween2 = nil
do
local properties = {
CFrame = part.CFrame * CFrame.Angles(math.rad(75), math.rad(180), math.rad(-90))
}
tween1 = TweenService:Create(part, info, properties)
end
do
local properties = {
CFrame = part.CFrame * CFrame.Angles(math.rad(75), math.rad(0), math.rad(90))
}
tween2 = TweenService:Create(part, info, properties)
end
while true do — you should avoid loops like this in general, but that’s for you to change
tween1:Play()
wait(3) — you can also use tween1.Completed:Wait() if you want to play it when the first tween is completed
tween2:Play()
— there’s no point in adding a wait() here, you’re already yielding, I suggest you wait for the tween to complete.
end
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local part = script.Parent
local tween1, tween2
do
local properties = {
CFrame = part.CFrame * CFrame.Angles(math.rad(75), math.rad(180), math.rad(-90))
}
tween1 = TweenService:Create(part, info, properties)
end
do
local properties = {
CFrame = part.CFrame * CFrame.Angles(math.rad(75), math.rad(0), math.rad(90))
}
tween2 = TweenService:Create(part, info, properties)
end
while true do
wait(2)
tween1:Play()
wait(2)
tween2:Play()
end
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local part = script.Parent
local tween1, tween2
do
local properties = {
CFrame = part.CFrame * CFrame.Angles(0, 0, 10)
}
tween1 = TweenService:Create(part, info, properties)
end
do
local properties = {
CFrame = part.CFrame * CFrame.Angles(0, 0, -10)
}
tween2 = TweenService:Create(part, info, properties)
end
while true do
wait(2)
tween1:Play()
wait(2)
tween2:Play()
end
Just copy and paste the Orientation of your choice into one of your tweens
Also if you really want, here’s it a bit simplified.
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local part = script.Parent
local tween1, tween2
local prop1 = {CFrame = part.CFrame * CFrame.Angles(0, 0, 10)}
local prop2 = {CFrame = part.CFrame * CFrame.Angles(0, 0, -10)}
tween1 = TweenService:Create(part, info, prop1)
tween2 = TweenService:Create(part, info, prop2)
while true do
wait(2)
tween1:Play()
wait(2)
tween2:Play()
end