Any help or alternative with connecting combat script

I’m making a fighting game as one would know from the 100’s of other posts i’ve made lol.

When spawning in the hitbox I use a variable called “canconnect” to make sure the hitbox doesn’t spam fire.

When using that, If I were to hit something and then another player does. The other player cannot hit.
I’m using a serverscript in serverscriptservice to do all the connecting stuff. If any experienced people know any alternatives to using canconnect. Or if I should rework it entirely, That would be much appreciated.
Here’s the script w/o canconnects,

local PunchEvent = game.ReplicatedStorage.Events.PunchEvent
local StunModule = require(game.ReplicatedStorage.Modules.Stun)
local stunevent = game.ReplicatedStorage.Events.Stun
local players = game:GetService("Players")
local OnConnect = game.ReplicatedStorage.Events.OnConnect
local GrantKill = require(game.ReplicatedStorage.Modules.DataStores.Kills)


local HitboxModule = require(game.ReplicatedStorage.Modules.Stun["HitboxV.1"])

PunchEvent.OnServerEvent:Connect(function(player)
	local character = player.Character
	local Humanoid = character:FindFirstChild("Humanoid")
	local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
   local hitbox = HitboxModule.Generate(Vector3.new(3,3,3), Vector3.new(0,0,2.3), character, HumanoidRootPart, 0)
	hitbox.Touched:Connect(function(hit)
		if hit.Parent ~= Humanoid then
			local hithum = hit.Parent:FindFirstChild("Humanoid")
			if hithum:GetAttribute("Parry") == true then
				local parryanim = Instance.new("Animation")
				parryanim.AnimationId = 'rbxassetid://17637392225'
				local parrytrack = hithum:FindFirstChild("Animator"):LoadAnimation(parryanim)
				parryanim:Destroy()
				parrytrack:Play()
				StunModule.parry(Humanoid, 2)
			elseif hithum:GetAttribute("Parry") == false and hithum:GetAttribute("Blocking") == false then
				StunModule.stun(hithum, 0.5, 10)
				OnConnect:FireClient(player, hithum)
				GrantKill.Kill(player, hithum)
			elseif hithum:GetAttribute("Blocking") == true then
				print("blocked")
			elseif hithum.Health == 0 or hithum.Health < 0 then
				print("already dead")
		   end
		end
	end)
end)
3 Likes

Don’t use BasePart.Touched for anything related to hitboxes. They’re somewhat useful for things like a touch trigger or a damaging part in an obby, but that’s about it. Here’s the typical alternatives:

  • Magnitude: Detects the distance between one point and another, which acts like a sphere in practice. Cheap and great for when your hitboxes are roughly even in all dimensions.
  • GetPartBoundsInBox(): Using a CFrame for position and Vector3 for size, it can easily make any kind of box shape you desire, perfect for more classic fighting game-style hitboxes.
  • Raycast Interpolation: At a very frequent interval, a raycast is fired from where one point was the last interval and the current interval, often done with multiple times along different parts of a sword for example. Harder to adjust than others, but laser-precise.

Anyways, for your main question, you don’t really need to worry about the client spamming requests to attack as long as you simply check if they’d be capable to on the server.

2 Likes

Nice, I actually genuinely never knew about this. Thanks for the tip

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.