Length of number error

Hello developers,
I am having a problem figuring out what part of this code is the problem. Could someone help me identify the problem.
Here is the error and the code.

local function AnimateElementIn(Element)
	Element:TweenSize(UDim2.new(0, 281, 0, 281),"Out","Linear",0.25,true)
end	

local function AnimateElementOut(Element)
	Element:TweenSize(UDim2.new(0, 103, 0, 103),"Out","Linear",0.25,true)
end	

icon.selected:Connect(function()
	local Emote_Folder = gui:FindFirstChild("Wheel"):WaitForChild("Emotes")
	for _,Frame in pairs(Emote_Folder:GetChildren()) do
		local TweenInfo = TweenInfo.new(
			0.25, -- time to tween
			Enum.EasingStyle.Linear, -- easing style
			Enum.EasingDirection.Out, -- easing direction
			0, -- number of times to repeat
			false, -- should it repeat
			0.25 -- delay between each tween
		)

		Frame.MouseEnter:Connect(function()

			local tween = TweenService:Create(Frame:WaitForChild("Wheel_Image"), TweenInfo, {ImageTransparency = 0.25})
			tween:Play()


			for Key,Element in pairs(Emote_Folder:GetChildren()) do
				if tonumber(Key:sub(#Key)) > tonumber(Frame.Name:sub(#Frame.Name)) then
					AnimateElementIn(Element)
				end
			end
		end)

		Frame.MouseLeave:Connect(function()
			local tween = TweenService:Create(Frame:WaitForChild("Wheel_Image"), TweenInfo, {ImageTransparency = 0.5})
			tween:Play()
			for Key,Element in pairs(Emote_Folder:GetChildren()) do
				if tonumber(Key:sub(#Key)) > tonumber(Frame.Name:sub(#Frame.Name)) then
					AnimateElementOut(Element)
				end
			end
		end)
	end
end)

1 Like

The Key in Emote_Folder:GetChildren() is already a number, as GetChildren() returns a table where the key is the index, and the value is the instance.

1 Like

Sorry for sounding like an idiot but could you also give an example because I’m having a hard time understanding what you are saying? (First time working with keys and more advanced tween sorry.)

That’s okay. On the documentation I linked to, there is example code that demonstrates how you’d use :GetChildren() in an i,v for loop:

-- Generic for-loop example

local children = workspace:GetChildren()

for i, child in children do
    print(child.Name .. " is child number " .. i)
end

In your case, you took the i (which you named Key), and tried to use it like a string, when it’s actually a number.

That begs the question, why are you converting the frame’s name into a number? I’m sure you could make it easier to get the order by using the LayoutOrder property instead.

1 Like

Thank you so much! This really helps me out a lot. :+1:

1 Like

I’ve fixed it now and I noticed that the easiest way to fix it was to either, Rewrite that part of the code or delete the line with the error on it. Problem solved code still works the same but without the error. Thank you so much for helping me out still. :+1: :+1: :+1:

1 Like

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