This is the script: local tool = script.Parent local canDamage = false
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if not humanoid then return end if humanoid.Parent ~= tool.Parent and canDamage then humanoid:TakeDamage(25) else return end canDamage = false
end
local function slash() local str = Instance.new("StringValue") str.Name = "toolanim"--tool animation str.Value = "Slash" str.Parent = tool canDamage = true end
tool.Activated:Connect(slash) tool.Handle.Touched:Connect(onTouch)
it has a local script too but that's for the animation. I want it to have the cooldown because if it doesn't people will be spam clicking and instakilling other players.
You can make a variable on the top and it will refer to a number. Then, add wait(thevariable)
before canDamage = false
. If you are confused, this is what I mean.
cooldown = 3 --You make this at the top so you can adjust it more convenient local tool = script.Parent local canDamage = false local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if not humanoid then return end local function onTouch(otherPart) if humanoid.Parent ~= tool.Parent and canDamage then --You check if the player can attack here canDamage = false --We make the player cannot attack once they activate the tool. humanoid:TakeDamage(25) wait(cooldown) --Then, wait the 3 seconds then we make the player can attack again. canDamage = true --After that, we make the player can attack again. else return end end local function slash() local str = Instance.new("StringValue") str.Name = "toolanim" str.Value = "Slash" str.Parent = tool canDamage = true end tool.Activated:Connect(slash) tool.Handle.Touched:Connect(onTouch)