Player (that got hit) plays an animation after getting hit with tool by player

basically, i have a tool that is using raycast hitbox (not sure if thats important) and when it hits another player it damages them and should make the player that got hit play an anim, like reacting to the hit, but the anim never plays.

CODE (server script):

	newHitbox.OnHit:Connect(function(hit, humanoid)
	local HitByBat = humanoid.Animator:LoadAnimation(Bat.HitByBat)
	local KnockoutFall = humanoid.Animator:LoadAnimation(Bat.KnockoutFall)
	local KnockoutLoop = humanoid.Animator:LoadAnimation(Bat.KnockoutLoop)
		local KnockoutRecover = humanoid.Animator:LoadAnimation(Bat.KnockoutRecover)
		--[[
		HitByBat.Parent = hit.Parent
		KnockoutFall.Parent = hit.Parent
		KnockoutLoop.Parent = hit.Parent
		KnockoutRecover.Parent = hit.Parent
		--]]
	print(hit)
	humanoid:TakeDamage(15)

end)

CONTEXT:
the event is kinda like a touch event, when the hitbox is hit, it will get what hit (for example, the hit could be RightArm or Torso) it and the humanoid of the thing that hit it.

2 Likes

What does it print? Do all the Prints; print?

1 Like

yes they all print, but i commented out this part HitByBat.Parent = hit.Parent as it results in an error:
The Parent property of HitByBat is locked, current parent: NULL

bruhhh how did i not notice this, i never actually played the anims :expressionless:

No. It can’t Print after an error, so it didn’t print the last Print.

You are goin to have to read the output from the Prints an figure-out what is going on.

I know nothing about Animation, but this looks like a code fragment. It probably does not collect the Humanoid. Who knows if it even gets the part hit…

There must be othee code relating to this…

It’s time to go back to your original model of how to do what you’re trying to do (You should be moding proven scripts which you are sure work already. (Search for better)…), Put a Print every line, and run and re-run it, until you are sure what every line dioes Look-up lines you do not understand in the Wiki.
Become an expert in tthat piece of code. Then mod it one line at a time…

Then come back here and teach me how animatinns are done…

i already solved this, and yes this is a code fragment, i understand everything in the code, just a simple mistake of forgetting to play the anims bruv