Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I Store Tables in a Table?

I have tried this code and it is returning "nil" when I try to print out Chests[2]. Any help?

local Chests = {
	DragonChest = {100,10000,100000,100000000};
}


function Open(Character, Player, Chest)
	print(Character.Name, Player.Name, Chest[2])
	--[[
	local CameraChanger = script.CameraManip:Clone()
	CameraChanger.Parent = 
	--]]
end



script.Parent.Touched:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("Head") then --check if cash is enough then subtract
		local char = Hit.Parent
		local plr = game.Players:GetPlayerFromCharacter(char)
		Open(char, plr, Chests)
	end
end)

3 comments

0

Yes

0

I think your issue is your essentially trying to print the name of the table, which might be your issue. Try indexing the actual Table.

0

What you have could be called a 2 dimensional table.

1 answer

✓ Accepted answer

You need to get a reference to the name of the table as well, that's DragonChest, or else you will be trying to get a reference to the value of the table Chests that has the key (or index) number 2.

Here is the script:

local Chests = {
    DragonChest = {100,10000,100000,100000000};
}


function Open(Character, Player, Chest)
    print(Character.Name, Player.Name, Chest[2])
    --[[
    local CameraChanger = script.CameraManip:Clone()
    CameraChanger.Parent = 
    --]]
end



script.Parent.Touched:connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("Head") then --check if cash is enough then subtract
        local char = Hit.Parent
        local plr = game.Players:GetPlayerFromCharacter(char)
        Open(char, plr, Chests.DragonChest) -- HERE!!
    end
end)

If you have any questions, leave a comment below. Thanks! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.