How do I insert an object into a table and make its index a string?

I’ve been trying to insert my sounds and animations into a table and have their indexes as a string which is their object names but I don’t know how to do that lol

I’m trying to achieve something like this:

local animations = {
   ["PunchAnim"] = part.PunchAnim;
   ["KickAnim"] = part.KickAnim;

Here’s my script:

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local animations = {

local sounds = {

	for _, z in pairs(shorp:GetDescendants()) do
		if z:IsA("Animation") then
            local anim = char:FindFirstChild("Animator", true):LoadAnimation(z)
			table.insert(animations, anim)
	for _, z in pairs(shorp:GetDescendants()) do
		if z:IsA("Sound") then
			table.insert(sounds, z)

animations[anim.Name] = anim


how the hell did i not know it was that easy :broken_heart: :broken_heart: :broken_heart:

I’m trying this and it just will not work, I checked with a print(unpack(Table)) to see the table’s contents, and it just returns " - "

You could just try printing the table itself unpack isn’t needed lol

From past experience it will just return the table’s name which is usually a scramble of numbers and letters, so that is why I use unpack. This was the first result I tried and yet, I get nothing as a result other than the " - ", with the spaces.

Edit: After trying the fix with the print changed despite the doubt in my mind, I achieved the required result. Sorry for being a complete and utter goofball, g’day.

1 Like

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