I am creating a punching script, the damage script isn't working the way I want it?
GOAL: PUNCHING SCRIPT ONKEYPRESS - R ANIMATION ACTIVATES THEN DOES DAMAGE (ONLY ON ACTIVATION)
So this damage script is supposed to do damage on activation (onKeyPress) not when it hits direct humanoid.
This damage script is entirely seperate from the main punching script, I will now explain,
PROBLEM:
For example:
If I touch a humanoid while that punching (local) script is in the backpack, it takes damage, it is supposed to do damage on the KeyPress activation, and I don't know any other way..
THE DAMAGE IS A REGULAR SCRIPT, THE PUNCHING SCRIPT IS A LOCAL SCRIPT.
Damage Script:
01 | Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) |
03 | local char = Player.Character |
04 | local torso = char:findFirstChild( "Torso" ) |
05 | local rightarm = char:findFirstChild( "Right Arm" ) |
07 | function onDamage(rightarm) |
08 | if rightarm.Parent:FindFirstChild( "Humanoid" ) ~ = nil and rightarm.Parent.Name ~ = script.Parent.Name then |
10 | rightarm.Parent.Humanoid.Health = rightarm.Parent.Humanoid.Health - 0.8 |
18 | rightarm.Touched:connect(onDamage) |
The punching localscript is a script that activates an animation and gives XP while cloning the damage script to do damage:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | Player = game.Players.LocalPlayer |
03 | mouse = Player:GetMouse() |
05 | repeat wait() until Player.Character |
07 | local char = Player.Character |
08 | local torso = char:findFirstChild( "Torso" ) |
09 | local leftarm = char:findFirstChild( "Left Arm" ) |
10 | local rightarm = char:findFirstChild( "Right Arm" ) |
16 | local function onInputBegan(input,gameProcessed) |
17 | if input.KeyCode = = Enum.KeyCode.R and HoldVariable = = 0 then |
19 | if leftarm or rightarm.BrickColor = = BrickColor.new( 'Really black' ) then |
20 | local hum = game.Players.LocalPlayer.Character.Humanoid |
21 | local anim_feet = hum:LoadAnimation(script.Parent.PunchAnim) |
22 | local current = anim_feet |
24 | local fd = script.Parent.PunchDamage:clone() |
26 | Player.Data.Xp.Value = Player.Data.Xp.Value + 460 |
35 | UserInputService.InputBegan:connect(onInputBegan) |