Player = game.Players.LocalPlayer
repeat wait() until Player.Character
c = Player.Character
mouse = Player:GetMouse()
mouse.TargetFilter = workspace.AntiMouse
UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.Q then
script.Function:FireServer("Projectile", c.HumanoidRootPart.CFrame, mouse.hit.p)
local debounce = false
end
end)
I need help adding a cooldown to this because its spammable, and the character can spam magic projectiles which is what i dont want.The first script is for the key bind and the second script is for the projectile and when it hits a object or character an explosion would happen. Can someone help me with a cooldown and where would i put it? At the end? I've tried looking into debounce but it wont work. I hope someone can help me, thanks.
script.Parent.OnServerEvent:connect(function(Player, Action, V1, V2)
local c = Player.Character
if Action == "Projectile" then
local P = Instance.new("Part")
P.Name = Player.Name.."Projectile"
P.Transparency = 1
P.Size = Vector3.new(2,2,2)
P.CFrame = V1*CFrame.new(0,0,-2)
P.CFrame = CFrame.new(P.Position, V2)
P.Parent = workspace.AntiMouse.Projectiles
P.CanCollide = false
game.Debris:AddItem(P,10)
local PFX = script.ProjectileFX:clone()
PFX.Parent = P
PFX.Enabled = true
local BV = Instance.new("BodyVelocity")
BV.maxForce = Vector3.new(25000,25000,25000)
BV.Velocity = P.CFrame.lookVector*25
BV.Parent = P
local Trigger = false
P.Touched:connect(function(Hit)
if Trigger == false and Hit.Parent.ClassName ~= "Accessory" and Hit.Parent ~= c and Hit.Name ~= Player.Name.."Projectile" and Hit.Parent ~= workspace.AntiMouse.FX then
Trigger = true
P.Anchored = true
PFX.Enabled = false
game.Debris:AddItem(P,1)
for i=1,3 do
local FX = game.ServerStorage.FX.CustomMeshFX:clone()
FX.Color = Color3.fromRGB(255,255,255)
FX.CFrame = P.CFrame
FX.Parent = workspace.AntiMouse.FX
game.Debris:AddItem(FX,2)
end
local Reg = Region3.new(P.Position-Vector3.new(6,6,6),P.Position+Vector3.new(6,6,6))
local RTable = workspace:FindPartsInRegion3(Reg, c)
for i,v in pairs(RTable) do
if v.Name == "HumanoidRootPart" and v.Parent:findFirstChild("Humanoid") and v.Parent:findFirstChild("ProjectileDeb") == nil then
local Deb = Instance.new("BoolValue")
Deb.Name = "ProjectileDeb"
game.Debris:AddItem(Deb,0.2)
v.Parent.Humanoid:TakeDamage(5)
local debounce = false
end
end
end
end)
end
end)

2 comments
Where would i put this?
replace script #1 with it