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

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

Asked by 7 years ago
Edited 7 years ago

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)

0
because it fires whenever the arm is touched, not when you punch & arm is hit wackem 50 — 7y
0
...huh? so line 16 is the problem...How would I change it? Clakker200 5 — 7y
0
ContextActionService is probably the best way to do that. GoldenPhysics 474 — 7y
0
okay thanks Clakker200 5 — 7y
0
Still cant figure it out Clakker200 5 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

Ad

Answer this question