Make tween access a table and the Child Properties

Basically the script is I am trying to make a main menu with compact scripting as you can see. I am wondering why I am getting an error as the title says. There weren’t any relevant answers from what I’ve looked up to my intentions so I made this post.

I made the script to make it so when I press a button such as play, it will tween the other GUI’s to go to 1.2 (Which is outside the screen) but going straight down, which is why I mentioned menu.Position because I want each UI not clicked to go straight down. How would I make an approach to make a tween access the menu.Position and make it access the table?

local ts = game:GetService("TweenService")

local ScreenGUI = script.Parent.Parent

local UItween = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)



local menus = {
	ScreenGUI.Settings,
	ScreenGUI.Play,
	ScreenGUI.Credits,
	ScreenGUI.Shop
	
}

function selectMenu(SelectedMenu)
	
	for _, menu in pairs(menus) do
		if menu == SelectedMenu then
			print(SelectedMenu)
		else
			local UIout = ts:Create(menu, UItween, {UDim2.new(menu.Position, 0, 1.2, 0)})
			UIout:Play()
		end
	end
end

ScreenGUI.Play.MouseButton1Click:Connect(function()
	selectMenu(ScreenGUI.Play)
end)
ScreenGUI.Settings.MouseButton1Click:Connect(function()
	selectMenu(ScreenGUI.Settings)
end)
ScreenGUI.Credits.MouseButton1Click:Connect(function()
	selectMenu(ScreenGUI.Credits)
end)
ScreenGUI.Shop.MouseButton1Click:Connect(function()
	selectMenu(ScreenGUI.Shop)
end)

What exactly is the error in the output? could you also send a picture of your gui layout?

Unable to Cast to Dictionary. On the line UIout is mentioned.

Alright i did a bit of testing and figured it out-
the issue here was the line of code where you defined the tween
you wrote:
local UIout = ts:Create(menu, UItween, {UDim2.new(menu.Position, 0, 1.2, 0)})
but this doesn’t define what value you’re changing in the tween. It should say
local UIout = ts:Create(menu, UItween, {Position = UDim2.new(menu.Position, 0, 1.2, 0)})
the “Position=” part is the issue.

2 Likes

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