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

The punching script does not hurt the other player, what should I do?

Asked by
xsodar 19
4 years ago

So this localscript is supposed to throw a punch animation, and if the punch hit another player it should lose -10 health. The thing is that the animation works okay, but it does not give any damage on the other player. How can I fix this/improve my script?

local userInputService = game:GetService("UserInputService")

local PunchValue = false
local db = false
local leftPunch = script.LeftPunch
local rightPunch = script.RightPunch
wait(0.1)

local player = game.Players.LocalPlayer
local char = player.character
local hum = char.Humanoid
local leftHand = char.LeftHand
local rightHand = char.RightHand
local humanoidRootPart = char.HumanoidRootPart

local leftPunchTrack = hum:LoadAnimation(leftPunch)
local rightPunchTrack = hum:LoadAnimation(rightPunch)

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.F and db == false then
        db = true
        print("Player pressed down the F key")


        if PunchValue == false then
            PunchValue = true
            leftPunchTrack:Play()

        elseif PunchValue == true then
            rightPunchTrack:Play()
            PunchValue = false

            leftHand.Touched:connect(function(hit)

    print(hit)
    if hit == humanoidRootPart then
        local human = hit:FindFirstChild("Humanoid")
        human.Health = human.Health -10
    end
end)

rightHand.Touched:connect(function(hit)
    print(hit)
    if hit == humanoidRootPart then
        local human = hit:FindFirstChild("Humanoid")
        human.Health = human.Health -10
    end
end)                    
        end
        wait(1.5)
    db = false  
    end

end)



Thanks, Xsodar

0
Script seems fine, problem might be that since it's on the client the server doesn't detect the health gone down. Try using a remote event to deduct the health. User#32819 0 — 4y
0
I did do that but I got an error, but I will try it again, thanks :) xsodar 19 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

if this is a localscript, Try using RemoteEvent beacuse The damage will not be in the server. And also I recommend you to use

human:TakeDamage(Damage_Here)

instead of using:

human.Health = human.Health - 10

I am not sure if i can make a Complete Script To fix it.

but if you're not sure what RemoteEvents are i suggest you to read this

I hope it atleast give you a little bit of help

Ad

Answer this question