So I have a script on the combat system, but I need to make it so that the NPS which I hit played animation punch, but the problem is that I do not know how I get humanoid, NPC to play it animation. This is how I do it on the player:
local load = humanoid:LoadAnimation(animation)
load:Play()
animation:Destroy()
but how do we do it on the NPS (player) we hit?
I’ll tell you right away that I need to get an NPS in the local script, which is at tool
You could use Touched event on a part that belongs to the tool, it will return a part that collided with the tool, the NPC.
Or use Raycasting to find whats in front of the Player when activated the tool, if the Player activates the tool infront of the NPC, the ray will return the NPC to the script to be used
local function OnTouched(otherPart, Head, Torso)
print("Touch started: " .. otherPart.Name)
if otherPart == Head or Torso then
wait(0.3)
print("It's working")
print(Head.Parent)
else
print("Try to find better")
end
end
Well, I wrote this script, but even when I touch the head of the enemy still writes the second. I’m a little confused about how do I take away the touch of a Humanoid, from touching other parts
pathtoobject.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not game.Players:GetPlayerFromCharacter(hit.Parent) then
print("It works")
end
end
end