Destroy a tool if it's not being used

Hello there! I was wondering how can I make it so if a tool is not being used at a certain time, it disappears.

I tried to write a script that checks if it’s not being used and then destroy but it doesn’t work:

local tool = script.Parent

if tool.Equipped == false then
	wait(5)
	script.Parent.Handle:Destroy()
end

What I want to achieve: If the tool is not being used for 10 seconds it destroys.
If it’s equipped then it won’t be destroyed.

  • Any help is appreciated :slight_smile:

Your script currently check if it is equipped only one time.
You can use loops such as while or repeat in order to make your wish true

local tool = script.Parent
local cooldown = 0

while wait(1) do
   if tool.Equipped == false then
       cooldown = cooldown + 1
       if cooldown >= 10 then
          tool:Destroy()
       end
   else cooldown = 0
   end
end

Made it as simple as it possible, and here how it works:
This script checks every second if tool is equipped. If not, it will increase cooldown until it will reach number 10 and then, it will destroy tool.

3 Likes

Here’s a better script

function check()
    local tool = script.Parent

    if tool.Equipped == false then
	wait(10)
	tool:Destroy()
     else return
      end
end
while wait(0.06) do
      check()
end
1 Like

Well, I put that but it still not working.
image

As you see here, the tools are not being destroyed, but anyways thanks for the help :slight_smile: really appreciated :smiley:

I put the script, but it still not working :confused: The tools are still there even if I wait a lot, but anyways thanks for the help :smiley:

Thanks. I will try to devise a better script now
Actually maybe the dude who is typing will
Yeah this dude below me

Am I right that script located in Tool object?

2 Likes

Yes, the script is inside the tool. So it is good to be script.Parent

Then try to achieve your result by puting the script in the Handle Basepart or whatever it is, not sure what is the problem but this might help

2 Likes

That has no effect really, he could just call Tool.Handle

Alright i will try, thank you!

local tool = script.Parent
local cooldown = 0

function onEquipped()
    cooldown = 0
end
tool.Equipped:connect(onEquipped()

while wait(1) do
    if not tool.Equipped then
        if cooldown >= 10 and not tool.Parent:FindFirstChild("Humanoid") then
            tool:Destroy()
        elseif not tool.Parent:FindFirstChild("Humanoid") then
            cooldown = cooldown + 1
        end
    end
end

This one might help, I really dunno what is the problem

2 Likes

I tried to call the Handle as well.

Tools still there, but i don’t know what’s wrong with the script
image

Tried with while true do and while wait do

I tried with all the scripts you sent me and mine as well, but it still not working. And it doesn’t print any mistake or something in the output.

Thanks for being helping me, but the scripts still not working.

I tried to set up another script but doesn’t work.

All the scripts seem to be working perfectly, as the output doesn’t print any errors or warnings.

Anyways, thank you! :slight_smile:

1 Like

Solved! I got it writing a new script:

while true do
	wait(5)
	if script.Parent.Parent:FindFirstChild("Humanoid") or script.Parent.Parent.Name == "Backpack" then
		--Do nothing
	else
		wait(1)
		script.Parent:Destroy()
		break
	end

end

Thank you all for helping me! :smiley:

1 Like

you’re welcome. Glad you found a script to solve it yourself.