i want to add a cooldown to this old wepon script i made, can someone help me do that?
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(5) else return end canDamage = false end local function slash() local str = Instance.new("StringValue") str.Name = "e" --idk why i made it e, i just edited the script that i used for an old game str.Value = "Slash" str.Parent = tool canDamage = true end tool.Activated:Connect(slash) tool.Handle.Touched:Connect(onTouch)
didn't understand what you mean by cooldown, damage? clicking?
local tool = script.Parent local canDamage = false local Cooldown = false local WaitTime: number = 0.3 --// anything 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(5) else return end canDamage = false end local function slash() if Cooldown then return end Cooldown = true local str = Instance.new("StringValue") str.Name = "e" --idk why i made it e, i just edited the script that i used for an old game str.Value = "Slash" str.Parent = tool canDamage = true wait(WaitTime) Cooldown = false end tool.Activated:Connect(slash) tool.Handle.Touched:Connect(onTouch)