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:
Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) local char = Player.Character local torso = char:findFirstChild("Torso") local rightarm = char:findFirstChild("Right Arm") function onDamage(rightarm) if rightarm.Parent:FindFirstChild("Humanoid") ~= nil and rightarm.Parent.Name ~= script.Parent.Name then for i = 1,6 do -- change this to change damage rightarm.Parent.Humanoid.Health = rightarm.Parent.Humanoid.Health - 0.8 CanCollide = false wait(0.0001) end end wait(0.025) end 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:
local UserInputService = game:GetService("UserInputService") Player = game.Players.LocalPlayer mouse = Player:GetMouse() repeat wait() until Player.Character local char = Player.Character local torso = char:findFirstChild("Torso") local leftarm = char:findFirstChild("Left Arm") local rightarm = char:findFirstChild("Right Arm") enabled = true HoldVariable = 0 local function onInputBegan(input,gameProcessed) if input.KeyCode == Enum.KeyCode.R and HoldVariable == 0 then HoldVariable = 1 if leftarm or rightarm.BrickColor == BrickColor.new('Really black') then local hum = game.Players.LocalPlayer.Character.Humanoid local anim_feet = hum:LoadAnimation(script.Parent.PunchAnim) local current = anim_feet current:Play() local fd = script.Parent.PunchDamage:clone() fd.Parent = rightarm Player.Data.Xp.Value = Player.Data.Xp.Value + 460 fd.Disabled = false wait(0.7) end wait(0.2) HoldVariable = 0 end end UserInputService.InputBegan:connect(onInputBegan)