I just want a basic punch tool for a fighting game kinda like oof combat but a bit more advanced.
I was working with a script that created the punch tool gui but when you equipped the tool it wouldn’t actually show the animation or hurt the npc or the player.
I have tried a bunch of stuff to try and get it to work and watched a bunch of tutorials, but i can’t seem to get it to work i am still very new to scripting and still struggle with it a lot.
I hope i am in the right category and not breaking any rules i am still new to the forum and i am just trying to develop my first game. If you guys have any tips or channels for me to learn scripting on please tell me.
You can check for the collision of a player’s hand, and if the part it collided with is a descendant of a character, then that character’s humanoid would be damaged.
I do not recommend you do this detection through a LocalScript as exploiters could easily fire this event damaging whoever they want.
The only local part of the punch should be the animation itself, moving the fist forward allowing the server to detect the touches. The client-side should be explanatory, but this is a brief idea of what the server-side code would probably look like:
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local Hand1 = char:WaitForChild("LeftHand")
local Hand2 = char:WaitForChild("RightHand")
Hand1.Touched:connect(HandTouched)
Hand2.Touched:connect(HandTouched)
local function HandTouched(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid and Humanoid.Parent ~= char then
Humanoid.Health = Humanoid.Health - 1 -- subtract 1 health
end
end
end)
end)
Of course, you would need to check with the client to make sure that they are trying to punch, so maybe have a remote event that tells the server when a client is punching so their idle hand doesn’t do damage. Hope this helps!
Practice makes perfect, the more you code the better you’ll get. If you ever have trouble understanding a concept, the Roblox Api Reference can usually be very helpful or you could always ask for help in #help-and-feedback:scripting-support like you did here. Glad I could help!