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

10 comments
Can you also post your LocalScript which fires the event?
ok, i'll see if i can
added
Can you explain whats you don't want to happen, and what's happening? I am very confused
yeah its hard to explain
And line 18 sets isAttacking to false, even though it's already false?
So you don't want it to trigger when it touches the humanoid, only when it's in a "Punching" Animation?
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
mb im back
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