Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want to get a cool down on my weapons. But how?

Asked by 3 years ago
Edited 3 years ago

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.

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
thanks Iivinglit24 0 — 3y
0
i just didnt want people to spam click Iivinglit24 0 — 3y
0
Uh, that's how you can solve it. NotTheChara 191 — 3y
0
You want explanation? NotTheChara 191 — 3y
View all comments (9 more)
0
sure and in studio it isnt working Iivinglit24 0 — 3y
0
wait maybe i could let you into the game in studio and you do the code for the cooldown? Iivinglit24 0 — 3y
0
Sure, I guess.. NotTheChara 191 — 3y
0
Wait, try the script again. I think it should work now. NotTheChara 191 — 3y
0
i enabled collaborative editing but when i go to the permissions page it says i need to turn it on... Iivinglit24 0 — 3y
0
I edited my answer, I think the script should be able to work now. NotTheChara 191 — 3y
0
ok i have to go for a little bit Iivinglit24 0 — 3y
0
its not damaging Iivinglit24 0 — 3y
0
it didnt work btw Iivinglit24 0 — 3y
Ad

Answer this question