Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add damage to my punches?

Asked by 6 years ago

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

Log in to vote
2
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

0
What is "character" in the example code? OptiBloxxer 9 — 6y
0
@OptiBloxxer the character who is punching DanzLua 2879 — 6y
0
So do I have to create a variable? OptiBloxxer 9 — 6y
0
And I'm only using R6, and I replace RightHand with RightArm the output says it's not apart of the model. OptiBloxxer 9 — 6y
View all comments (6 more)
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" DanzLua 2879 — 6y
0
@OptiBloxxer DanzLua 2879 — 6y
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. OptiBloxxer 9 — 6y
0
character["Right Arm"].Touched DanzLua 2879 — 6y
0
So is "character" character = player.Character? OptiBloxxer 9 — 6y
0
@OptiBloxxer sure DanzLua 2879 — 6y
Ad

Answer this question