(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.