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

How would I script this so whenever I punch it will damage the player?

Asked by 4 years ago
Edited 4 years ago

I have a punch script in a local script and server script. I use local script to detect when he punches, create a cool down and play an animation. The server is used to damage the punched player.

How would I make it work? Im really new to combat systems and damaging the humanoid.. please help me..

Local script:

local AnimPunch = Instance.new("Animation", Character)
AnimPunch.AnimationId = "rbxassetid://3673137593"
local PunchAnim = Humanoid:LoadAnimation(AnimPunch)

Pressed = false

UIS.InputBegan:Connect(function(k)
    if k.KeyCode == Enum.KeyCode.F and Pressed == false then
        Pressed = true
        PunchAnim:Play()
        punchEvent:FireServer()
        wait(0.3)
        Pressed = false
    end
end)

Server script:

function punch_plr(p)
    local char = p.CharacterAdded:Wait()

    local hit = char.RightArm --I tried finding whenever a player touches my hand it will damage him (this is the punching hand)

    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
        hum:TakeDamage(2)
    end 

end

punchEvent.OnServerEvent:Connect(function(p)
    punch_plr(p)
end)
1
make it a local script then when touched send a remote event that damages the humanoid, i mean, the touched event locally, because animations are local and are not replicated maumaumaumaumaumua 628 — 4y

Answer this question