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 5 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

01local player = game.Players.LocalPlayer
02local db = true
03local db2 = false
04local damage = false
05 
06local anim = Instance.new("Animation")
08 
09game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
10    if hit.Parent:FindFirstChild("Humanoid") and db2 and not damage and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
11        if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
12            game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
13        end
14    end
15end)
View all 31 lines...

and code of damage script

01game.Players.PlayerAdded:Connect(function(player)
02    player.CharacterAdded:Connect(function(char)
03        local sound = game.ServerStorage.Punch:Clone()
04        sound.Parent = char:WaitForChild("Head")
05    end)
06end)
07 
08 
09game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player, humanoid)
10    if humanoid.Health >= 10 then
11        humanoid.Health = humanoid.Health - 10
12    elseif humanoid.Health < 10 then
13        humanoid.Health = 0
14    end
15 
16    player.Character.Head.Punch:Play()
17    wait(0.5)
18end)

Please Help And Thanks You.

1 answer

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

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

01local player = game.Players.LocalPlayer
02local db = true
03local db2 = false
04local damage = false
05local hitHumanoids = {}
06local anim = Instance.new("Animation")
08 
09game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
10    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
11        if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
12            game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
13        hitHumanoids[hit.Parent] = true
14        end
15    end
View all 33 lines...

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

0
Thx you OrewaKamidaa 40 — 5y
Ad

Answer this question