Punch script is not working

I want to make a punch tool.

Output: image
image

local script:
local plr = game.Players.LocalPlayer
local char = plr.Character
local tool = script.Parent
local canattack = tool:WaitForChild(“CanAttack”)

tool.Equipped:connect(function()
local idle script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
idle:Play()
'local choose = math.random(1,2)
canattack.Value = true
if choose == 1 then
local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Swing1)
swing1animation:Play()
elseif choose == 2 then
local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Swing2)
swing2animation:Play()
end
end)

tool.Deactivated:connect(function()
local hum = char:WaitForChild(“Humanoid”)
for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
anim:Stop()
end
end)

script:
local tool = script.Parent
local canattack = tool:WaitForChild(“CanAttack”)
local plr = tool.Parent.Parent
local char = plr.Character
local leftArm = char:WaitForChild(“LeftHand”)
local rightArm = char:WaitForChild(“RightHand”)

leftArm.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild(“Humanoid”)
if canattack.Value == false then
if hum then
canattack.Value = true
hum:TakeDamage(10)
wait(0.5)
canattack.Value = false
end
end
end)

rightArm.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild(“Humanoid”)
if canattack.Value == false then
if hum then
canattack.Value = true
hum:TakeDamage(10)
wait(0.5)
canattack.Value = false
end
end
end)

1 Like

Try formatting your code a bit better so I can understand what Im actually trying to fix

edit : The animation your trying to play is nil basically meaning it cant find it

Do you mean tabbing my code in?

No I mean using “```” to format it

example:

print("Something")

Dont wait for child after deactivated the tool, just reference it up at the top of the script

move

local hum = char:WaitForChild("Humanoid")

to the top of the script

obviously after youve declared the character and the player

I still does not work image

It says something on line 5 is nil so show me line 5 please

local hum = char:WaitForChild(“Humanoid”)

The character for some reason is nil, try to set char to CharacterAdded:Wait()