Using table.insert() With a String as the index

Hello! I am wanting to make a function that creates new tables with names of instances as the index/key for each value. How can I do this? I am currently trying to use table.insert() buti am getting a “Cannot cast value to object” error.

local function setUpNewTable()
	local newArray = {}
	for i,Button in pairs(animationButtonList:GetChildren()) do
		if Button.ClassName == "TextButton" then 
			table.insert(newArray,Button.Name,humanoid:LoadAnimation(Button.Animation.AnimationId))	
		end
	end
	return newArray
end
1 Like

newArray[Button.Name] = humanoid.Animator:LoadAnimation(Button.Animation.AnimationId)

table.insert only inserts to arrays

3 Likes