Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i add a cooldown to this old wepon script?

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)

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.