How would I make a time limit for a tool?

Hi. I’m trying to make a hover tool here.
The issue is that there is no time limit on it at all so you can just use it forever which would be too overpowered.

So how would I make it so you can only use this tool for 5 seconds then it unequips and you can’t use it for another 5 seconds?
I don’t know how to make this anymore clear other than this but basically when you equip the tool 5 seconds after equipping it, it unequips itself and then you can’t equip the tool for 5 seconds.

Looking up the issue on google and even here on the devhub didn’t give me any results sadly which is why I’m asking here.
Here’s the script I’m using:

1 Like

Someone else had the same question and got a solution click Here

1 Like

I already checked that but that didn’t solve anything for this one as I’m not just trying to have a cooldown with when the tool can be used but also when you are using the tool.

I want the player to only be able to use the tool for 5 seconds.
The link you have there only tells me how to make it so the tool can’t be equipped for a certain ammount of time.

Can you please explain what you are trying to make the tool do (besides 5 seconds cooldown)? I think you used scripts from a tool giver model incorrectly (just found a tool giver with the exact same script)

The tool just makes you hover in the air and you’re able to move freely with it.
Nothing extra at all and the tool is in the StarterPack as you can see on the screenshot.
There aren’t any tool givers or anything.

1 Like

Simple make like this:
local debounce = 1
debounce == 1 then
event that u want to happen then
debounce = 2
wait(5)
Hope it Solved your problem :slight_smile:

1 Like

You could create a variable, set it to false, name it ‘cooldown’. Before running your code after the player clicks, you can write if cooldown == false then and set cooldown to true if it is false. After your code runs, (whatever it is) place a wait(5) at the end, then set cooldown to false again.

local cooldown =false
Clicked:Connect(function() -- Make sure to edit this event
   if cooldown == false then
        cooldown=true
        -- write code
        wait(5) -- If your code takes time, make sure to subtract from that
        cooldown=false
   end
end)
2 Likes

I’ll try that thanks!
I’ll update soon

1 Like

No problem man have a good day / night
Just dont forget to make “==” so it can check current value

1 Like

I’ll try this as well. Whatever works. I’ll update as soon as I can get on PC

1 Like

I tried both, and I’m actually so confused. I have no idea how to apply these two to this script since the script I’m using already has a local debounce and it basically clashes with the one in the replies. I’ll update if I find a solution

Update: The script inside the tool doesn’t actually do anything. I removed the script and the tool worked even without it. I’m gonna update this thread with the solution.

A debounce to prevent it from being spammed and the cooldowntime as the amount of seconds you need in order to fly again

local debounce = false
local cooldowntime = 5

function hoverboard()
	if not debounce then
		debounce = true

		flyingstuffhere()

		wait(cooldowntime)
		debounce = false
	end
end

I had a friend help me with this but I tested this reply as well and this works too so I’m marking it as solution.