I made a punching animation but I am trying to make my animation do damage to dummies, but the animation wont play! If anyone can tell me what I'm doing wrong that would help a lot.
My code:
player=game.Players.LocalPlayer
mouse=player:GetMouse()
function KeyD (key)
key=key:lower()
local hotkey=script.Hotkey
local char=player.Character
if key==hotkey.Value then
local dance=Instance.new("Animation")
dance.AnimationId="https://web.roblox.com/Punch-item?id=476354090"
local animloader=char.Humanoid:LoadAnimation(dance)
animloader: Play()
end
end
script.Parent.Touched:connect(function(part)
local human=part.Parent:findFirstChild("Humanoid")
if human then
if human.Parent.Name~=script.Parent.Parent.Parent.Name and
CanDamage == true and script.Parent.Parent.Swinging.Value==true then
CanDamage=false
human:TakeDamage(20)
wait(1.7)
CanDamage=true
end
end
end)
mouse.KeyDown:connect(KeyD)

1 comment
Does this do damage to a real player? The "TakeDamage" function does not work on NPC humanoids. To deal damage to NPC's you should subtract the humanoids health.