I have a punch script, everything was working well until, I added the damage script. Now whenever I touch an object (even without punching), it damages the object
My script :
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local humanoid = player.Character:FindFirstChild("Humanoid")
local animate
local hand = humanoid.Parent:WaitForChild("RightHand")
local function round(n)
return math.floor(n + 0.5)
end
mouse.KeyDown:Connect(function(key)
if key == "z" then
game.ReplicatedStorage.Event.AddStrength:FireServer()
local animation = Instance.new("Animation", player.Character)
animation.AnimationId = "rbxassetid://5390069207"
animate = humanoid:LoadAnimation(animation)
animate:Play()
end
end)
mouse.KeyDown:Connect(function(key)
hand.Touched:Wait()
hand.Touched:Connect(function(hit)
if key == "z" then
if hit.Parent.Humanoid then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - round(player.leaderstat.Strength.Value / 100)
end
end
end)
end)

3 comments
You should make a damage script that activates once the user presses z and deactivates after the animation is complete.
Ok
Thanks for the tip