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

Is there a way to fix this punch script I made?

I made a basic punch script but there is a problem. I made a local script in starterpack and made a keydown function,when you press e your arms move and and it makes a punch noise after that it executes this script below which deals the damage, the problem is When a humanoid touches the left arm it automatically does damage when I don't press "e" any help?

local debounce = false

function onDamage(Part)
	if not debounce then
		debounce = true
	if Part.Parent:FindFirstChild("Humanoid")~= nil and Part.Parent.Name ~= "script.Parent.Name" then 
		 script.Parent.hit:Play()
	
			Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -1.4
			wait(1)
			debounce = false
		end
	end
end

script.Parent.Parent.Parent.Character["Left Arm"].Touched:connect(onDamage)

5 comments

0

because it fires whenever the arm is touched, not when you punch & arm is hit

0

...huh? so line 16 is the problem...How would I change it?

0

ContextActionService is probably the best way to do that.

0

okay thanks

0

Still cant figure it out

1 answer

Does the script check to see if the "e" key is pressed? The script should check to see if debounce = false and if the "E" key was pressed by the player.

If you are checking for both of those, then I really can't suggest any solutions. Perhaps you made some sort of typo, or typed "parent" instead of "Parent".

I hope my answer helped you.

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