Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I add damage to my punches?

So I have a script for when you press Q if plays a punching animation, does anyone know how to make it so it damages? I wanna make sure it only enables damaging once the key is pressed

1 answer

what you should do is create a punching variable

local punching = false

then when you click q you make the bool true, after the animation is over set it back to false

Now you should create a touched event for the end of the arm, specifically the RightHand & LeftHand if you are using R15, if R6 just the Right Arm and Left Arm will work.

Example, I made it so that when the righthand is touched it should check that the thing that touched it is not from that character and that there is a humanoid in its parent.

local punching = false

character.RightHand.Touched:connect(function(hit)
	if hit.Parent~=character and hit.Parent:FindFirstChild("Humanoid")~=nil and punching==true then
		hit.Parent.Humanoid:TakeDamage(10)
	end
end)

This example is for the RightArm, you should have to set it up for the LeftHand as well if this was for R15 and the other way around for R6.

10 comments

0

What is "character" in the example code?

0

@OptiBloxxer the character who is punching

0

So do I have to create a variable?

0

And I'm only using R6, and I replace RightHand with RightArm the output says it's not apart of the model.

0

This was only an example, not a complete script, in R6 there is no RightHand, there is a "Right Arm" and a "Left Arm"

0

@OptiBloxxer

0

@DanzLua I know that theres no RightHand in R6, but how do you put Right Arm into the script? Since if I replace RightHand with RightArm it doesn't work. If I make a space as in "Right Arm" To replace "RightHand" in the code it doesn't work.

0

character["Right Arm"].Touched

0

So is "character" character = player.Character?

0

@OptiBloxxer sure

This discussion is preserved as it was. New answers, comments, and votes are closed.