Cooldown, how to make?

Script:

local tool = script.Parent
local event = script.Parent:WaitForChild("ThrowingEvent")
local debris = game:GetService("Debris")

event.OnServerEvent:Connect(function(player)
		
	local dynamite = tool.Handle:Clone()
	dynamite.Parent = workspace
	dynamite.CanCollide = true
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	local dir = hrp.CFrame.LookVector + hrp.CFrame.UpVector
	dynamite.VectorForce.Force = dir * 10
	wait(0.2)
	dynamite.VectorForce.Enabled = false
	wait(0.6)
	dynamite.ExploseSound:Play()
	
	local vfx = workspace.Explosion_1:Clone()
	vfx.Parent = workspace.vfx
	vfx.Position = dynamite.Position
	vfx.Anchored = true
	vfx.Attachment.Explosion.Enabled = true
	vfx.Attachment.Smoke.Enabled = true
	dynamite.Transparency = 1
	dynamite.Anchored = true
	dynamite.CanCollide = false
	debris:AddItem(dynamite, 2.2)
	
	wait(0.5)
	
	vfx:Destroy()
	
end)

Local Script:

local uis = game:GetService("UserInputService")
local tool = script.Parent
local anim = tool:WaitForChild("Throw")
local track = nil
local event = tool:WaitForChild("ThrowingEvent")
local equipped = false
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:FindFirstChild("Animator") or Instance.new("Animator", hum)
local track = animator:LoadAnimation(anim)

local function throw()
	wait(0.5)
	event:FireServer()
	
	wait(2)
end

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		track:Play()
		wait(2)
	end
	
	if input.UserInputType == Enum.UserInputType.Touch then
		track:Play()
		wait(2)
	end
end)


mouse.Button1Down:Connect(throw)

So the question is how to make a player can not quickly throw dynamite. Where do I put wait()? After all, at the moment the player can very quickly press and throw a bunch of dynamite, how to limit it in this?

just do

local debounce

local function yourFunction()
	if debounce == true then return end
	debounce = true
	
	-- do your stuff here
	
	task.wait(1)
	debounce = nil
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.