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

Punch script needs to hit if it actually hits??

Asked by 4 years ago
Edited 4 years ago

(I posted this before but I accidentally deleted it out of ignorance sorry) Basically,I made a punch script that NEARLY works perfectly however if I activate it with the KeyCode then nothing happens until my right arm makes contact with a humanoid, in which it damages it. The problem is that it's supposed to do damage when the right arm makes contact with the humanoid once as in only damage if it actually hits the humanoid, not until the right arm touches the humanoid again.

Sever Script:

game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player,humanoid)
    local char = player.Character
    local Players = game:GetService("Players")
    local rarm = char["Right Arm"]
    local larm = char["Left Arm"]
    local rleg = char["Right Leg"]
    local lleg = char["Left Leg"]
    local Animation = Instance.new("Animation")
      LoadAnimation:Play()
    local debounce = false

    rarm.Touched:connect(function(hit)
     if not debounce then
        debounce = true
        local Human = hit.Parent.Humanoid
        if not hit.Parent:FindFirstChild('Torso') then return end
        if hit.Parent:FindFirstChild('Torso') then 
         if Human:TakeDamage(25)then
            debounce = false
end
        end
        end
     end)
    end)            

Local Script (script that fires the code)

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer;
local Char = plr.Character or plr.CharacterAdded:Wait()
local RS = game:GetService('ReplicatedStorage')
local punchevent = RS.Punch
local kickevent = RS.SideKick
local Players = game:GetService("Players")
local root = Char:WaitForChild('HumanoidRootPart')
local rightarm = Char["Right Arm"]
local isAttacking = false

UIS.InputBegan:Connect(function(i, processedevent) 
      if processedevent then return end
    if i.KeyCode == Enum.KeyCode.G then
        punchevent:FireServer()
        --kickevent:FireServer() (i disabled this on purpose)
          wait(0.3)
        isAttacking = false
        end
end)

there should be nothing wrong with the localscript but for reference here it is. i also cant put debounce below the end, because then it wont stop attacking. im basically trying to make it so it will only do damage if it hits. the problem is very hard to explain but basically do damage only if the attack has hit. in this case if i press the keycode, if the attack hits then it would do damage, however if the attack misses and if i make contact with my arm again (without pressing the keycode that fires the attacking event) it will still do damage, which is my current problem. please help me out on this.

0
Can you also post your LocalScript which fires the event? killerbrenden 1537 — 4y
0
ok, i'll see if i can NecroMancerSam 0 — 4y
0
added NecroMancerSam 0 — 4y
0
Can you explain whats you don't want to happen, and what's happening? I am very confused marine5575 359 — 4y
View all comments (6 more)
0
yeah its hard to explain NecroMancerSam 0 — 4y
0
And line 18 sets isAttacking to false, even though it's already false? marine5575 359 — 4y
0
So you don't want it to trigger when it touches the humanoid, only when it's in a "Punching" Animation? marine5575 359 — 4y
0
This should work, Hiting, in this case, is the same thing. so can you explain what your trying to accomplish? Also please upload a video of what the script is doing, so I can fix it better marine5575 359 — 4y
0
mb im back NecroMancerSam 0 — 4y
0
i cant upload videos but what im trying to say is that i need to make it not damage if it hasnt hit anything, not damage the next time my right arm makes contact with a humanoid, but basically yeah its what you said only when its in a punching animation. i tried putting a wait() then debounce false but thats too slow so if you can come up with anything i can try then yeah NecroMancerSam 0 — 4y

Answer this question