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