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

2 comments
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.
I did do that but I got an error, but I will try it again, thanks :)