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

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

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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

if child:IsA("Tool") or child:IsA("HopperBin")  then
0
I tried that but since The HopperBin Tools don't leave your backpack when equipped it doesn't work Gwolflover 80 — 8y
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. emaster2013 30 — 8y
Ad

Answer this question