I have made a hitting animation for a weapon but I don’t know how to do damage with that weapon when it clicks, how do I do it?
You can shoot a Raycast out of the player when they punch by firing a RemoteEvent to server. When the raycast hits something, detect if it’s a player, and also check how far that player is from the attacking player. If it’s close enough, then do the damage to the victim.
You can check distance between objects using Magnitude.
Add a local script on the tool with an Activated function. Then, whenever the tool gets activated check if the tool touched a player using the Touched function. Finally, if the tool touched another player use a Remote event to tell the server to damage that player.
evercyan’s rpg kit can solve that. Just ungroup the ‘UNGROUP in serverscriptservice’ model into serverscriptservice and once you ungroup, delete every thing except for GameRemoteHandler, expand the gameremote handler in workspace and delete every module script except for DamageEvent, go in the actual remote handler and delete every code in there except the DamageEvent code. Sadly that is for R6 only. if your game is R15, i have made an R15 version of the script.
also delete the rpg kit folder in workspace for reasons
also add a remote event and call it “DamageEvent” exactly like that or the script might not work. Also fire the damage event when a weapon hits something with a humanoid or if it’s a gun, fire the damage event when the weapon’s bullet hits something with a humanoid
Is it a hitting weapon? If yes, then as part of your mousedown/click event, you add a Connect to detect if it hits a Humanoid:
local touched = weapon.Touched:connect(function(part)
if part.Parent and part.Parent:FindFirstChild("Humanoid") then
local humanoid = part.Parent.Humanoid
-- Damage your Humanoid taking away 10 Health
humanoid:TakeDamage(10)
end
end)