How to make a simple fist system!

Hello dear devs! Today ill be showing y’all how to make a simple fist system.

First,create a remoteEvent in replicated storage and then create a local script in StarterPlayer ----> StarterCharacterScripts and insert this in!

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local anim2 = Instance.new("Animation")
local playerArms = player.Character:WaitForChild("RightHand") -- The fist
local remoteEvent = game:GetService("ReplicatedStorage").FistEvent -- change "FistEvent" to the name of your remote event!
mouse.Button1Down:Connect(function()
	if playerArms then
			remoteEvent:FireServer(player)
		anim2.Name = "PunchAnim"
		anim2.AnimationId = "rbxassetid://your_animation_id"
		local track
		track = script.Parent.Humanoid.Animator:LoadAnimation(anim2)
		track.Priority = Enum.AnimationPriority.Action4
		track:Play()
		script.Enabled = false
		wait(2)
		script.Enabled = true
	end
end)

after you’ve done that insert a script inside “serverscriptservice” and put this in!

game.ReplicatedStorage.FistEvent.OnServerEvent:Connect(function(player)
	local playerArms = player.Character:FindFirstChild("RightHand")
	playerArms.Touched:Connect(function(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
	if humanoid then
			local plr = game.Players:GetPlayerFromCharacter(otherPart.Parent)
			if humanoid.Health > 0 then
					humanoid:TakeDamage(20)
					script.Enabled = false
					print("Damaged")
					wait(2)
					script.Enabled = true
				end
			end
	end)
	end)

after that, everything should work. Enjoy!

4 Likes

You are using a lot of bad practices and also not explaining anything that’s going on, also wait() is deprecated and you should be using task.wait().

3 Likes

I know it’s kinda off topic but i just wanted to ask if the hitbox should be handled client or server side both of them have adventanges and disadventages, just wanted to know wich one is better

I’ve never made any serious combat systems so I can’t really give you any advice.

1 Like

I respect what you’re doing helping people.
And I love your energy so have a good day.

hitboxes client sided are more accurate, you should do them with sanity checks on the server. for example making sure the player youre hitting is within reasonable distance.

Thank you for providing this, however, no offense, but anyone who knows a little bit of scripting, I would recommend make your own, for three reasons:

This will work, but is not very customizable

.touched event is unreliable.

It takes like an hour or two to make your own

Once again, thank you for making this.

i agree that .touched event is unreliable but i just had no other idea how to detect if a player hit someone with his arm so yeah, i used touched.

1 Like

This looks really messy and really impractical. You should format and space out your code to make it more readable to other developers, especially since this is targeted towards newer ones. You should also explain what your code does a bit more.

Instead of .touched you can use GetPartBoundsInBox/GetPartBoundsInRadius. You might need to study the parameters a bit, but when you learn it, it’s easy to work with. As people above me said, you should also do hitboxes on the client side, but with checks on the server, and use task.wait instead of wait.

1 Like

Why you use Enum.AnimationPriority.Action4 ? I would just use action simply

i used action4 in case a player has other animations, and the other animations may ruin the fist animation, to be honest action may also do the same thing as action4 but i just use action4 everytime.

This is never disconnected so that’s a bad thing because it could cause a memory leak.

Do you have any visuals for what this is supposed to end up looking like? Videos and/or a place with the code would be a nice thing to have in the post.

ima just send a video here, but it will be hella laggy (and bad quallity) cuz ima use f12.