Unable to cast Dictionary

local ObjGui = script.Parent
local ObjFrame = ObjGui.ObjectiveFrame
local ObjText = ObjFrame.ObjectiveFrame.TextLabel
--
local ObjInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0)
local InPos = {Position = {-0.022, 0},{0.783, 0}}
local OutPos = {Position = {-0.4, 0},{0.783, 0}}
--
local TweenIn = TS:Create(ObjFrame, ObjInfo, InPos) -- Error Here
local TweenOut = TS:Create(ObjFrame, ObjInfo, OutPos)

The line where it says Error Here the output always says “Unable to cast Dictionary.”
I think it is because of the InPos/OutPos being like that format, but I do not know how to tween the position of Gui’s when the position is like that.

Any help is appreciated!

1 Like

Issue may be that these are not correctly set. It should be set with Vector3.new() as put in the documentation.

1 Like

Gui objects have a method to tween their position: GuiObject:TweenPosition() which requires a Udim2 value. However if you want to use TweenService then that’s not how you tween a position. Positions are represented by Vector2 and Udim2; in this case since you are working with GUI objects you must use Udim2 as the position value for GUI objects is made out of scale and offset coordinates, in conclusion you will need to define the position value in the properties dictionary like this:

local propertiesToTween = {
    Position = Udim2.new({ScaleX, OffsetX}, {ScaleY, OffsetY}))
}
3 Likes

It isn’t pretty yet, but this should be the fixed script:

local ObjGui = script.Parent
local ObjFrame = ObjGui.ObjectiveFrame
local ObjText = ObjFrame.ObjectiveFrame.TextLabel

local ObjInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0)
local InPos = -0.022
local OutPos = -0.4

local TweenIn = TS:Create(ObjFrame, ObjInfo, {Position = UDim2.new(InPos,0,0.783)})
local TweenOut = TS:Create(ObjFrame, ObjInfo, {Position = UDim2.new(OutPos,0,0.783)})

-- Make sure to also Play the tween
3 Likes
local ObjGui = script.Parent
local ObjFrame = ObjGui.ObjectiveFrame
local ObjText = ObjFrame.ObjectiveFrame.TextLabel
--
local ObjInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local InPos = {Position = Udim2.fromScale(-0.022, 0.783)}
local OutPos = {Position = Udim2.fromScale(-0.4, 0.783)}
--
local TweenIn = TS:Create(ObjFrame, ObjInfo, InPos) 
local TweenOut = TS:Create(ObjFrame, ObjInfo, OutPos)

If the offset for the ui is 0, consider using Udim2.fromScale() rather than Udim2.new(). Just simpler overall.

2 Likes

Thank you! This works perfectly!

1 Like

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