I want to make a punch tool.
Output:
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)