Basicly I am making one tool (I used cooldown for the player dont spamm and I used debounce for the player cant use it when is not equipped) when I click button1Down works but the cooldown doesnt go back.
I only can make the function happen 1 time
Gif:
local debounce = false
local cooldown = 1
local isCoolingDown = false
--------Checks if Mouse is Clicked--------
tool.Equipped:Connect(function(Mouse)
button1DownListener = Mouse.Button1Down:Connect(function()
if not debounce then
debounce = true
isCoolingDown = true
RemoteEvent:FireServer(bagParts.PaintLocation.Position, bagParts.PaintLocation.Orientation, Mouse.Hit.p)
Shoot1:Play()
SpraySound:Play()
end
end)
wait(cooldown)
isCoolingDown = false
end)
---Full script---
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local tool = script.Parent
local bagParts = tool:WaitForChild("BagParts")
local Shoot1
local idle
local SubwayBag_Sound = script.Parent:WaitForChild("BagSound")
local SpraySound = script.Parent:WaitForChild("SpraySound")
local debounce = false
local cooldown = 1
local isCoolingDown = false
tool.Equipped:Connect(function()
local char = plr.Character or plr.CharacterAdded:Wait()
game.ReplicatedStorage.ConnectM6D:FireServer(tool.BagParts.BodyAttach)
char.Torso.ToolGrip.Part0 = char.Torso
char.Torso.ToolGrip.Part1 = tool.BagParts.BodyAttach
local Humanoid = char:FindFirstChild("Humanoid")
idle = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
Shoot1 = Humanoid:LoadAnimation(script:WaitForChild("Attack1"))
idle:Play()
end)
tool.Unequipped:Connect(function()
game.ReplicatedStorage.DisconnectM6D:FireServer()
if not idle then return end
idle:Stop()
Shoot1:Stop()
SpraySound:Stop()
end)
--------UserInputService Setup--------
local userInput = game:GetService("UserInputService")
--------Remote Event Setup--------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("SprayShootEvent")
--------Checks if Mouse is Clicked--------
tool.Equipped:Connect(function(Mouse)
button1DownListener = Mouse.Button1Down:Connect(function()
if not debounce then
debounce = true
isCoolingDown = true
RemoteEvent:FireServer(bagParts.PaintLocation.Position, bagParts.PaintLocation.Orientation, Mouse.Hit.p)
Shoot1:Play()
SpraySound:Play()
end
end)
wait(cooldown)
isCoolingDown = false
end)
--------Unequip gun--------
tool.Unequipped:Connect(function()
debounce = false
if button1DownListener then
button1DownListener:Disconnect()
button1DownListener = nil
end
end)