I made a roblox punch script and it works
but when the player arm touches a player or npc it does damage even though the animation isn’t playing,
there is no error in the output
how can I fix this?
UIS.InputBegan:Connect(function(key)
if key.keyCode == Enum.UserInputType.MouseButton1 or Enum.KeyCode.F then
PunchAnim:Play()
if PunchAnim.IsPlaying then
script.Parent["Right Arm"].Touched:Connect(function(hit)
if hit.Parent.Humanoid and Dmg == false then
hit.Parent.Humanoid:TakeDamage(20)
Dmg = true
wait(1)
Dmg = false
end
end)
end
end
end)
Full Script
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local Humanoid = player.Character.Humanoid
local Dmg = false
local debounce = false
local Punch = script:WaitForChild("Punch")
local PunchAnim = Humanoid:LoadAnimation(Punch)
local Kick = script:WaitForChild("Kick")
local KickAnim = Humanoid:LoadAnimation(Kick)
UIS.InputBegan:Connect(function(key)
if key.keyCode == Enum.UserInputType.MouseButton1 or Enum.KeyCode.F then
PunchAnim:Play()
if PunchAnim.IsPlaying then
script.Parent["Right Arm"].Touched:Connect(function(hit)
if hit.Parent.Humanoid and Dmg == false then
hit.Parent.Humanoid:TakeDamage(20)
Dmg = true
wait(1)
Dmg = false
end
end)
end
end
end)