I have a punching animation that, upon the character’s arm colliding into another character, knocks the character back. However, even when the character’s arm collides into another character, an npc or even anything, the script does not detect it. Why does this happen?
inputevent.OnServerEvent:Connect(function(plr, key, arg1, arg2)
local char = plr.Character
if key == "Click" then
if arg1 == "true" then
local rightarm = char:WatForChild("Right Arm")
punch = rightarm.Touched:Connect(function()
--Knocking back enemy
end
else
punch:Disconnect()
end
end
end
Instead of Touched Events, make a part in front of the player and use that as the hit box and use PartBoundsInBox for hitboxes, its just a faster and more reliable way.
If you still want to go your way and not use @JAcoboiskaka1121 method then you would do something like this:
inputevent.OnServerEvent:Connect(function(plr, key, arg1, arg2)
local char = plr.Character
if key == "Click" then
if arg1 == "true" then
local rightarm = char:WaitForChild("Right Arm")
punch = rightarm.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local bv = Instance.new("BodyVelocity")
bv.Parent = hit.Parent.HumanoidRootPart
bv.Velocity = rightarm.Parent.HumanoidRootPart.CFrame.LookVector * -20
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
game:GetService("Debris"):AddItem(bv, 0.2)
end
end)
else
punch:Disconnect()
end
end
end)
I have also noticed that your code has some typos. (fixed them)