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

How to make the punch cooldown?

Asked by 4 years ago

How do I need to make it cooldown punch because there too op for every second i want to make it cooldown like like 1 second Here the code

local player = game.Players.LocalPlayer
local db = true
local damage = false

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset?id=3582012915"

game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not db and not damage and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
        if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
            damage = true
            game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
        end
    end
end)

game:GetService("UserInputService").InputBegan:Connect(function(input, event)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        db = false
        local playAnim = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):loadAnimation(anim)
        playAnim:Play()
        wait(5)
        damage = false
        db = true


    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This should work.

local player = game.Players.LocalPlayer
local db = true
local db2 = false
local damage = false

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset?id=3582012915"

game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and db2 and not damage and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
        if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
            game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
        end
    end
end)

game:GetService("UserInputService").InputBegan:Connect(function(input, event)
    if input.UserInputType == Enum.UserInputType.MouseButton1 and db then
        db = false
    db2 = true
    wait(.5)
    db2 = false
        local playAnim = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):loadAnimation(anim)
        playAnim:Play()
        wait(4.5)
        damage = false
        db = true


    end
end)
1
Thanks you OrewaKamidaa 40 — 4y
0
No problem, @OrewaKamidaa. Vinceberget 1420 — 4y
1
wait dude @Vinceberget its work but i can spam it when it was after cooldown OrewaKamidaa 40 — 4y
0
It should work better now Vinceberget 1420 — 4y
1
@Vinceberget OMG DUDE U ARE RLLY COOL OrewaKamidaa 40 — 4y
Ad

Answer this question