Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can I Store Tables in a Table?

Asked by
INOOBE_YT 387 Moderation Voter
7 years ago

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)
0
Yes xXLegendarySoldierXx 129 — 7y
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. xXLegendarySoldierXx 129 — 7y
0
What you have could be called a 2 dimensional table. GoldenPhysics 474 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

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! :)

Ad

Answer this question