How to make this punching script deal damage

You would make a variable that stores whether the person can damage someone or not. Then, if the variable is true, you can fire a RemoteEvent which damages the victim. Here’s an example i made, I haven’t tested it yet:

--Put this script in StarterCharacterScripts:
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Mouse = Player:GetMouse()
local PunchAnim = Humanoid:LoadAnimation(script:WaitForChild("Punch1Anim"))
local PunchAnim2 = Humanoid:LoadAnimation(script:WaitForChild("Punch2Anim"))
local KickAnim = Humanoid:LoadAnimation(script:WaitForChild("Kick1Anim"))
local RightArm = game.Players.LocalPlayer.Character["Right Arm"]
local LeftArm = game.Players.LocalPlayer.Character["Left Arm"]
local LeftLeg = game.Players.LocalPlayer.Character["Left Leg"]

local CanDamage = false
local Table = {RightArm, LeftArm, LeftLeg}
local NextAnim = 1 
local Cooldown = false

Mouse.Button1Down:Connect(function()
	if not Cooldown then
		Cooldown = true
		CanDamage = true

		if NextAnim == 1 then
			NextAnim = 2
			PunchAnim:Play()
					wait(0.5)	
				
	
		elseif NextAnim == 2 then
			NextAnim = 3
			PunchAnim2:Play()
					wait(0.5)	
				
			
		elseif NextAnim == 3 then
			NextAnim = 1
			KickAnim:Play()
					wait(0.5)	
				end
		
		
		
		local CurrentNextAnim = NextAnim
		
		Cooldown = false
		CanDamage = false
		wait(0.5)
		if CurrentNextAnim == NextAnim then 
			NextAnim = 1
		end
	end
end)

for i,v in pairs(Table) do
	v.Touched:Connect(function(h)
		if h.Parent:FindFirstChild("Humanoid") and CanDamage then
			CanDamage = false
			game.ReplicatedStorage.AttackEvent:FireServer(h.Parent) --Replace 10 with the amount of damage you want the victim to take!
		end
	end)
end
--And put this one in ServerScriptService:
local Remote = Instance.new("RemoteEvent")
Remote.Name = "AttackEvent"
Remote.Parent = game:GetService("ReplicatedStorage")

Remote.OnServerEvent:Connect(function(Player, Character)
	if Character:FindFirstChild("Humanoid") then
		Character.Humanoid:TakeDamage(10)
	end
end)
1 Like