Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

0

I did do that but I got an error, but I will try it again, thanks :)

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.