Unable to cast to Dictionary Error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to create a writable paper object that uses buttons with surface GUIS.

  1. What is the issue? Include screenshots / videos if possible!

I tried to add mouse hover animations by using tween service but I always came across an error:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I looked on the dev forums but none of the solutions helped me.

-- Set up --

local TweenService = game:GetService("TweenService")
local NoteTable = game.Workspace.Table
local buttons = script.Parent:FindFirstChild("Note Buttons")


-- Functions --

function ButtonTween(Object, Goal, Speed, Style, Direction)
	local TI = TweenInfo.new(Speed,Style,Direction, 0)
	local Goal = {CFrame = Goal}
	local Animation = TweenService:Create(Object, TI, {Goal})
	Animation:Play()
end



-- Code --
for a, b in pairs(NoteTable.Buttons:GetChildren()) do
	for i, v in pairs(buttons:GetChildren()) do
		local cFrame = b.CFrame;
		v.TextButton.MouseEnter:Connect(function(X, Y)
			ButtonTween(b, cFrame * CFrame.new(-0.1, 0, 0), 0.15, Enum.EasingStyle.Quad, Enum.EasingDirection.Out);
		end)
		v.TextButton.MouseLeave:Connect(function(X, Y)
			Do(b, cFrame * CFrame.new(0, 0, 0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out);
		end)
	end;
end

Note: Please let me know if you need any other information!

Just for reference, could you send a screenshot of the explorer tab with all the instances inside of the Notetable?

Hi.
I noticed you nested the “Goal” table into another table, this is most likely why it’s spitting out that error.

Change:

local Animation = TweenService:Create(Object, TI, {Goal}) 

To:

local Animation = TweenService:Create(Object, TI, Goal)

See if that works.

2 Likes

Hello, thank you so much it fixed the issue. Though I found another problem with my code. Whenever I hover over one button, all other buttons get tweened too.

Hello thanks for the reply, here’s the image:
image

That’s interesting, I can’t tell what’s happening by your code. Your code looks fine to me.

Is this a localscript in StarterGUI?

yes, here is the layout:
image

Ah, I think I see the issue now.

What is happening is that you are looping through all the UI textbuttons in the loop for the part buttons.
So basically it’s connecting all the textbutton events to tween every button as you loop through, instead of just the one.

You could change:

for a, b in pairs(NoteTable.Buttons:GetChildren()) do
	for i, v in pairs(buttons:GetChildren()) do
		local cFrame = b.CFrame;
		v.TextButton.MouseEnter:Connect(function(X, Y)
			ButtonTween(b, cFrame * CFrame.new(-0.1, 0, 0), 0.15, Enum.EasingStyle.Quad, Enum.EasingDirection.Out);
		end)
		v.TextButton.MouseLeave:Connect(function(X, Y)
			Do(b, cFrame * CFrame.new(0, 0, 0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out);
		end)
	end;
end

To:

for a, b in pairs(NoteTable.Buttons:GetChildren()) do
	local v = buttons:FindFirstChild(tostring(b)) -- I like doing tostring(Instance), in case it's nil we don't want it to error with .Name.
	if v then
		local cFrame = b.CFrame;
		v.TextButton.MouseEnter:Connect(function(X, Y)
			ButtonTween(b, cFrame * CFrame.new(-0.1, 0, 0), 0.15, Enum.EasingStyle.Quad, Enum.EasingDirection.Out);
		end)
		v.TextButton.MouseLeave:Connect(function(X, Y)
			Do(b, cFrame * CFrame.new(0, 0, 0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out);
		end)
	end
end

I hope I’ve done that correctly, I didn’t use a code editor.

1 Like

Ahhh I see the issue now. Thank you so much! God bless you.

1 Like