I'm trying to make a system which allows a player to shoot a spell, but, I don't want them to be able to continuously use the spell without a cool down. If there is no cool down, the player has the ability to use an auto clicker which spams the spell and creates a load of lag within game, hence why I would like to make one.
However, when I tried creating a cool down, I used a debounce but I kept getting errors and things kept going underlined then other functions of my script wouldn't work.. The script below is the fire script for one of my spells WITHOUT the cool down as mine didn't seem to work.. Please could someone help.
I would like the cool down to be a 0.5 second wait per click..
game.ReplicatedStorage.Powers.OnServerEvent:Connect(function(player, MouseHit, Handle)
if player.Spell.Value == "Water" then
local S1 = Instance.new("Part",workspace)
local S1b = Instance.new("BodyVelocity")
S1.CFrame = Handle.CFrame + Handle.CFrame.lookVector*3
S1.Anchored = false
S1.CanCollide = true
S1.formFactor = "Symmetric"
S1.Shape = "Ball"
S1.Size = Vector3.new(1,1,1)
S1.TopSurface = "Smooth"
S1.BottomSurface = "Smooth"
S1.Transparency = 0.5
S1.Elasticity = 1
S1.Friction = 0
S1.BrickColor = BrickColor.new("Bright blue")
S1b.Velocity = MouseHit.lookVector*100
S1b.Parent = S1
game:GetService("Debris"):AddItem(S1, 2)
local part = S1
part.Touched:connect(function(hit)
if hit.Parent then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if hum.Parent.Name == player.Name then
wait(0.01)
else
hum:TakeDamage(2)
S1:Destroy()
end
end
end
end)
end
end)
Thank you.

2 comments
Use debounce bro. wiki.roblox.com/index.php?title=Debounce
" I used a debounce but I kept getting errors and things kept going underlined then other functions of my script wouldn't work"