Clone not naming with table information

game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
 
 --< variables >--
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name) -- added WaitForChild
local bp = player.Backpack
local hum = char:WaitForChild("Humanoid")
local frame = script.Parent
local template = frame.Template
local equipped = Color3.fromRGB(255,0,50) -- icon transparencies
local unequipped = Color3.fromRGB(47,47,47)



local inputKeys = { -- dictionary for effective referencing
	["One"] = 
	{txt = "1"}, 
	{img = "rbxassetid://6023987358"},
	["Two"] = 
	{txt = "2"}, 
	{img = "rbxassetid://6024209316"},
	["Three"] = 
	{txt = "3"},
	{img = "rbxassetid://6023987116"},
	["Four"] = 
	{txt = "4"}, 
	{img = "rbxassetid://6023986983"},
	["Five"] = 
	{txt = "5"}, 
	{img = "rbxassetid://6023986887"},
	["Six"] = 
	{txt = "6"}, 
	{img = "rbxassetid://6023986784"},
	["Seven"] = 
	{txt = "7"}, 
	{img = "rbxassetid://6023986695"},
	["Eight"] = 
	{txt = "8"}, 
	{img = "rbxassetid://6023986621"},
	["Nine"] = 
	{txt = "9"}, 
	{img = "rbxassetid://6023986521"},
	["Zero"] = 
	{txt = "0"}, 
	{img = "rbxassetid://6023987470"}
}

local inputOrder = { -- array for storing the order of the keys
	inputKeys["One"],inputKeys["Two"],inputKeys["Three"],inputKeys["Four"],inputKeys["Five"],
	inputKeys["Six"],inputKeys["Seven"],inputKeys["Eight"],inputKeys["Nine"],inputKeys["Zero"],
}
	
--< functions >--
function handleEquip(tool)
	if tool then
		if tool.Parent ~= char then
			hum:EquipTool(tool)
		else
			hum:UnequipTools()
		end
	end
end

function create() -- creates all the icons at once (and will only run once)

	
	for i = 1, #inputOrder do
		
		local value = inputOrder[i]		
		local clone = template:Clone()
		clone.Parent = frame
		clone.Number.Image = value["img"]
		clone.Name = value["txt"]
		clone.Visible = true
		clone.BackgroundColor3 = unequipped
		
		local tool = value["tool"]
		if tool then
			clone.ToolImage.Image = tool.TextureId
		end

		clone.Tool.MouseButton1Down:Connect(function() -- click icon to equip/unequip
			for key, value in pairs(inputKeys) do
				if value["txt"] == clone.Name then
					handleEquip(value["tool"]) 
				end 
			end
		end)

	end	
	template:Destroy()
end

Pretty straightforward hotbar script that I found on toolbox and rescripted some of it, however, for some reason on function create() it prints Argument 1 Missing or nil
The error is that for some reason, the clone doesn’t get named with the create() function.

I don’t really know the reason, any help would be appreciated.
Thank you for reading :slight_smile:

1 Like

Your problem could be your dictionary
The right way of doing it is like this:

local inputKeys = {
    ["One"] = {txt = "1"; img = "rbxassetid://6023987358"}, 
    ["Two"] = {txt = "2"; img = "rbxassetid://6024209316"}
    -- etc
}

So each keys of the dictionary inputKeys (One, Two, Three, etc.) will contain another dictionary, with the keys txt and img.

The way you’re doing it, each keys of the dictionary inputKeys contains another dictionary with only the key txt. If we format your code in a more readable way:

local inputKeys = {
    ["One"] = {txt = "1"}, 

    {img = "rbxassetid://6023987358"},

    ["Two"] = {txt = "2"}, 

    {img = "rbxassetid://6024209316"}
}

You can see that the key One contains the dictionary {txt = "1"}, then you feed the dictionary inputKeys with {img = "rbxassetid://6023987358"} in an array-like way.
It’s the equivalent of doing this:

local inputKeys = {
    ["One"] = {txt = "1"}, 

    [1] = {img = "rbxassetid://6023987358"},

    ["Two"] = {txt = "2"}, 

    [2] = {img = "rbxassetid://6024209316"}
}

You can verify that by printing inputKeys[1] or inputKeys[2]:

local inputKeys = {
    ["One"] = {txt = "1"}, 

    {img = "rbxassetid://6023987358"},

    ["Two"] = {txt = "2"}, 

    {img = "rbxassetid://6024209316"}
}

print(inputKeys[1]["img"], inputKeys[2]["img"])

---> rbxassetid://6023987358   rbxassetid://6024209316

Could you send me the entire error? Or just which line the error occurs, I think there may be more to your problem than just the dictionary.

1 Like