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

How to make the attack strength equal to the time of punching?

Asked by 4 years ago

my punch cooldown is working but my damage script is also spam damage while punch cooldown still stop playing

here my punch cooldown code

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(0.5)
        damage = false
        db = true


    end
end)

and code of damage script

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local sound = game.ServerStorage.Punch:Clone()
        sound.Parent = char:WaitForChild("Head")
    end)
end)


game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player, humanoid)
    if humanoid.Health >= 10 then
        humanoid.Health = humanoid.Health - 10
    elseif humanoid.Health < 10 then
        humanoid.Health = 0
    end

    player.Character.Head.Punch:Play()
    wait(0.5)
end)

Please Help And Thanks You.

1 answer

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

The punches should no longer stack on the same humanoid/player.

local player = game.Players.LocalPlayer
local db = true
local db2 = false
local damage = false
local hitHumanoids = {}
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 and not hitHumanoids[hit.Parent] then
        if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
            game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
        hitHumanoids[hit.Parent] = true
        end
    end
end)

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


    end
end)

I used a dictionary to see if a player had already been hit, with the index being the humanoid.

0
Thx you OrewaKamidaa 40 — 4y
Ad

Answer this question