Why is my table seemingly empty

I am trying to make a boss fight system, which takes all folders in another folder, puts them in a table, and when the function is called with the cooresponding attack, the module script within runs. However, the attackTable is seemingly empty (i have tried every way of printing a table, and it does not print anything). print(v.Name) succesfully prints, and print(attacks.Name) also successfully prints. The script is located within a Server Script in a rig that is in Workspace.

local attacks = game.ReplicatedStorage:WaitForChild("attackFolder")
print(attacks.Name)
local attackTable = {}
for _, v in pairs(attacks:GetChildren())do
	if v.ClassName=="Folder" then
		table.insert(attackTable,v)
		print(v.Name)
	end
end


local function useAttack(attack_name)
	script.Parent.UsingAttack.Value = true
	local att = attack_name:Clone()	
	att.Parent = game.Workspace
	local module = att:FindFirstChildOfClass("ModuleScript") 
	require(module)
end

--boss AI here

useAttack(1)

script.Parent.UsingAttack.Changed:Connect(function(change)
	if script.Parent.UsingAttack.Value == false then
		useAttack(attackTable[math.random(1, #attackTable)])
		print("Using" .. #attackTable)
	end
end)

I don’t think the table is empty. It’s probably erroring when you call this function as 1 is an integer and not an instance, so when calling the function it runs local att = attack_name:Clone(). You can’t clone an integer, lol.

Doesn’t that take the cooresponding instance from the table though?

No. useAttack(1) will call the function using the value of 1 as an argument, not the value of index 1 from the table.

useAttack(attacksTable[1]) is how you would call the function using the value of the first index of the table as an argument.

2 Likes