Improving this simple combat script

This is a quick punching script that I made. Everything is good except one thing, I don’t like how you can hit people behind you. I’m thinking about raycasting from the characters humanoidrootpart position to the lookvector by 10. Would that be a good idea?

local Combat = game:GetService("ReplicatedStorage").Remotes.RemoteEvent1


local DmgTable = {
	Hit1 = 5;
	Hit2 = 6;
	Hit3 = 5;
	Hit4 = 6;
	Hit5 = 10;
}


local function Damage(Humanoid, Amount)
	Humanoid:TakeDamage(Amount)
end


Combat.OnServerEvent:Connect(function(Client, Combo) 
	print(DmgTable[Combo])
	
	for _, player in ipairs (game.Players:GetChildren()) do
		if player ~= Client and (Client.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude < 10  then
			Damage(player.Character.Humanoid, DmgTable[Combo])
			
		end 
	end
end)
	
	
	
	
	
1 Like

If you want to make it look more advanced and special, you should add hit effects and such.