How to when players fist hits other players face, the others player takes damage

when players fist (from animation) hits other players face, the others player takes damage. The onclick play animation works but I don’t know how to make the other players take damage.

This is where the script and animation is stored.
image

and here is the code:

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local mouse = player:GetMouse()
local animation = script.Animation

mouse.Button1Down:Connect(function()
	print("Clicked")
	local humanoid = character.Humanoid
	local animtrack = humanoid:LoadAnimation(animation)
	animtrack:Play()
end)
2 Likes

You can use a remote event to send a request to the server. Then, the server handles the attack.

Before the connection here closes, fire your remote. This remote event should be placed in ReplicatedStorage, and to fire it, just type in something like (remote variable - remove parentheses):FireServer()

Then, on the server, a .Touched connection for the Humanoid to check if it is the punching arm can handle the combat with a simple Humanoid check.
You also need to define a connection if you want the connection to be temporary.

(remote here).OnServerEvent:Connect(function(player)
    local character = player.Character
    if character:FindFirstChild("Stunned") then -- we will use a value here for debounce
        return -- dont do anything
    else
        -- oh yes
        -- did u know that calling :Connect on events returns a connection?
        local connection = character.Humanoid.Touched:Connect(function(hitPart, bodyPart)
            if bodyPart.Name:sub(1, 5) == "Right" then -- check if it is right arm
                local hum = hitPart.Parent:FindFirstChild("Humanoid") -- check if hit part is player
                if hum then
                    local tag = Instance.new("Folder", hum.Parent) -- apply tag to character
                    tag.Name = "Stunned"
                    hum:TakeDamage(25) -- Whatever number here
                end
            end
        end)

        wait(.5) -- the connection will be active for this long
        connection:Disconnect()
    end
    
end)

I think this should work.

3 Likes

wow it works!!! tysm for this, ill give you credits ingame

An entry level approach to this would include using the BasePart.Touched event on either the arm doing the punching (or some other part welded to this), and the Humanoid:TakeDamage function. Getting a little more advanced you may want to run this code on the server (with a Script instead of LocalScript), so you may need to take advantage of RemoteEvents (roblox.com).

The process would essentially be setting up an event listener for the part of the arm that when collided with, you want to cause damage. Whenever the ‘Punch’ is activated, set a variable - maybe isPunching equal to true. This way when your Touched event is triggered you can perform a check on this variable to decide whether damage should be dealt (otherwise damage would be dealt even when not punching). You will also need to locate the other player’s Humanoid from the part that was touched because the Touched event does not give direct access to the Humanoid.

A few other notes:

  1. You should implement some “debounce” within your mouse.Button1Down event (see code below)
  2. If would be more efficient to call the LoadAnimation function only once (per character spawn) instead of each time the mouse is pressed.

Here’s just a bit of sample code to get you started. This is implemented using a Tool:
BasicPunch.rbxl (23.3 KB)

1 Like