Unable to cast to dictionary while tweening UI

Hello, everyone.
I’ve spent hours trying to fix this bug, but can’t.
It’s “Unable to cast to dictionary” on line 15, which is local tween2 = TweenService:Create…

local TweenService = game:GetService("TweenService")

local function tweenGui(UIE, direction)
	local originalSize = UIE.Size
	local originalPosition = UIE.Position
	print(originalPosition)
	local UIelement = UIE
	local Direction = direction
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
	if Direction == true then
		local goal = UDim2.new(1, 100, 1, 0)
		local tween = TweenService:Create(UIelement, tweenInfo, goal)
		tween:Play()
	elseif Direction == false then
		local goal2 = originalPosition
		local tween2 = TweenService:Create(UIelement, tweenInfo, originalPosition)
		tween2:Play()
	end
end

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("ImageLabel") then
		v.MouseEnter:Connect(function()
			tweenGui(v,true)
		end)
		v.MouseLeave:Connect(function()
			tweenGui(v,false)
		end)
	end
end
2 Likes
local TweenService = game:GetService("TweenService")

local function tweenGui(UIE, direction)
	local originalSize = UIE.Size
	local originalPosition = UIE.Position
	print(originalPosition)
	local UIelement = UIE
	local Direction = direction
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
	if Direction == true then
		local goal = UDim2.new(1, 100, 1, 0)
		local tween = TweenService:Create(UIelement, tweenInfo, {Position = goal})
		tween:Play()
	elseif Direction == false then
		local goal2 = originalPosition
		local tween2 = TweenService:Create(UIelement, tweenInfo, {Position = originalPosition})
		tween2:Play()
	end
end

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("ImageLabel") then
		v.MouseEnter:Connect(function()
			tweenGui(v,true)
		end)
		v.MouseLeave:Connect(function()
			tweenGui(v,false)
		end)
	end
end

I changed The Lines of

local tween = TweenService:Create(UIelement,tweenInfo,goal)

To

local tween = TweenService:Create(UIelement,tweenInfo,{Position = goal})

Test it out, Might work.

uess you’re tweening something like the ui’s transparency, i’d suggest using TweenSize() and TweenPosition() depending on what your goal is. This would also remove any unnecessary lines of code.

To potentially fix your issue, try changing this line


local tween2 = TweenService:Create(UIelement, tweenInfo, originalPosition)

to


local tween2 = TweenService:Create(UIelement, tweenInfo, {Position = originalPosition})