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 5 years ago
Edited 5 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:

01local AnimPunch = Instance.new("Animation", Character)
02AnimPunch.AnimationId = "rbxassetid://3673137593"
03local PunchAnim = Humanoid:LoadAnimation(AnimPunch)
04 
05Pressed = false
06 
07UIS.InputBegan:Connect(function(k)
08    if k.KeyCode == Enum.KeyCode.F and Pressed == false then
09        Pressed = true
10        PunchAnim:Play()
11        punchEvent:FireServer()
12        wait(0.3)
13        Pressed = false
14    end
15end)

Server script:

01function punch_plr(p)
02    local char = p.CharacterAdded:Wait()
03 
04    local hit = char.RightArm --I tried finding whenever a player touches my hand it will damage him (this is the punching hand)
05 
06    local hum = hit.Parent:FindFirstChild("Humanoid")
07    if hum then
08        hum:TakeDamage(2)
09    end
10 
11end
12 
13punchEvent.OnServerEvent:Connect(function(p)
14    punch_plr(p)
15end)
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 — 5y

Answer this question