i got a bomber tool and it has a cooldown of 20 seconds
i want the name of the tool to show the cooldown how do i do it heres the local script of the tool:
wait(1)
local cooldown = 20 -- time you must wait (in seconds) between each orbital strike
--dont edit anything below this line
local tool = script.Parent
local run = game:GetService('RunService')
local debris = game:GetService('Debris')
local rs = game:GetService('ReplicatedStorage')
local plr = game:GetService('Players').LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local part = rs:WaitForChild('hover2')
local event = rs:WaitForChild('bombingRun')
local equipped = false
local cd = false
local onStep = function()
repeat wait() until cam:FindFirstChild('hover2')
cam.hover2.Position = mouse.Hit.p
end
tool.Equipped:Connect(function()
mouse.TargetFilter = cam
equipped = true
part:Clone().Parent = cam
run:BindToRenderStep('a',2000,onStep)
end)
tool.Unequipped:Connect(function()
equipped = false
run:UnbindFromRenderStep('a')
if cam:FindFirstChild('hover2') then
cam.hover2:Destroy()
end
end)
mouse.Button1Down:Connect(function()
if equipped and not cd then
cd = true
spawn(function()
for i = .5,.8,.05 do
run.Heartbeat:Wait()
cam.hover2.Transparency = i
end
cam.hover2.Transparency = .8
for i = .8,.5,-.05 do
run.Heartbeat:Wait()
cam.hover2.Transparency = i
end
cam.hover2.Transparency = .5
local a = part:Clone()
a.Position = mouse.Hit.p
a.Parent = workspace
debris:AddItem(a,3.5)
end)
event:FireServer(mouse.Hit)
wait(cooldown)
cd = false
end
end)
local Debounce = require(script.Parent.Debounce) -- any module script
-- code
if tick() - Debounce[player.UserId] >= MaxCooldown then -- we compare two times
Debounce[player.UserId] = tick()
-- code
end
Simply make module for storing debounces, if there will be error you can create each player’s debounce every time they join and remove it when they leave, after that you compare current time with debounce time and tell if it have ended, if yes then continue
Debounce is name of cooldown in programming, it’s used when we want to add cooldown to some stuff, there are also things like tables, with them you can store data, there is also tick() that allows you to get current time that passed from unix epoch. With those three components, you can save tick() to table under player, then after some time check if time you wanted to start your cooldown subtracted from current time is greater than cooldown, if it is then cooldown expired and code can run further
Note: don’t use wait, it can yield and break entire script, use task.wait() as it doesn’t yield, also it runs on 60 fps not 30
Scripting Manual i made manual for programming, you can use it to learn more