Help with Variables and If Statements

In my script I have an If Statement that Checks for a tool with a Value of “Slot1”. If this statement is true then it grabs the Tool and Parents it somewhere else.

The problem is I don’t know how to call the Specific Tool when more than one tool in the player’s backpack.

removed

I’m guessing you have multiple slots so here’s something you can do.

You probably want a function to access the different slots so here’s one that you could use.

local function findToolWithSlotName(slotName)
    local tool = nil
    for key, child in pairs(Backpack:GetChildren()) do
        if child:IsA("Tool") and child.SlotName.Value == slotName then
            tool = child
            break
        end
    end

    return tool
end

Then you could use it like
local tool1 = findToolWithSlotName("Slot1")
local tool2 = findToolWithSlotName("Slot2")
tool2.Parent = Hub

3 Likes