robloxapp-20240626-1242294.wmv (1.6 MB)
my code
local punchTool = script.Parent
local PunchAnimations = {
{
AnimationId = "rbxassetid://18216156939",
Part = "Right Arm"
},
{
AnimationId = "rbxassetid://18216154579",
Part = "Right Arm"
},
{
AnimationId = "rbxassetid://18216532641",
Part = "Left Arm"
}
}
local i = 0
local canAttack = true
local function getAnimation()
i = i % #PunchAnimations + 1
return PunchAnimations[i]
end
local connect: RBXScriptConnection
punchTool.Activated:Connect(function()
local char = script.Parent.Parent:: Model
local humanoid = char:FindFirstChild("Humanoid"):: Humanoid
local animator = humanoid:FindFirstChild("Animator"):: Animator
if canAttack then
local punch = getAnimation()
local animation = Instance.new("Animation")
local animTrack
animation.AnimationId = punch.AnimationId
animTrack = animator:LoadAnimation(animation)
if not animTrack.IsPlaying then
canAttack = false
animTrack:Play()
connect = char[punch.Part].Touched:Once(function(hit: BasePart)
local otherChar = hit.Parent
local otherHumanoid = otherChar:FindFirstChild("Humanoid"):: Humanoid
if otherHumanoid ~= humanoid then
otherHumanoid:TakeDamage(10)
end
end)
animTrack.Stopped:Wait()
animation:Destroy()
connect:Disconnect()
canAttack = true
end
end
end)