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

How can i describe in Lua that no tool is selected?

I have a script and I only want it to work if the player has no tools selected. How could I define no tools being selected? Basically what I'm asking is, how can I say in Lua "when the player has no tool selected"? Someone suggested this function below, but It only works for an actual tool, not a Hopperbin script based tool like I have.


function isToolEquipped()
    local character = player.Character
    if character then
        for _, child in next, character:GetChildren() do
            if child:IsA("Tool") then
                return true
            end
        end
    end
    return false 
end

Thanks for any help guys and let me know if I need to clarify anything!

1 answer

Check to see if the child is a HopperBin object as well.

if child:IsA("Tool") or child:IsA("HopperBin")  then

2 comments

0

I tried that but since The HopperBin Tools don't leave your backpack when equipped it doesn't work

0

Sorry, forgot about that! HopperBins have an "Active" property that is set to true when the bin is equipped. You can iterate over the players backpack and check if this property is true.

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