Custom hitbox system delay

Im working on a asymmetrical survival game (original right?)
the ONLY issue ive had in the creation process is these delayed hitboxes!! their messing me up!
anyone got any solutions?

also this is a modulescript, if you needed to know that

my code:

function Index.CreateHitbox(size, object, plr: Player)
	if game:GetService("RunService"):IsServer() then
		local current = 0
		local returning = nil

		local function CreatePart()
			local hitbox = Instance.new("Part", workspace.GameAssets.Hitboxes)
			hitbox.Anchored = true
			hitbox.Massless = true
			hitbox.CastShadow = false
			hitbox.CanCollide = false
			hitbox.Size = size
			hitbox.Color = Color3.fromRGB(255,0,0)    
			hitbox.Material = Enum.Material.ForceField	

			if object:IsA("Model") then
				if plr then
					local ping = plr:GetNetworkPing()
					local velocity = plr.Character.PrimaryPart.AssemblyLinearVelocity
					local baseCFrame = object.PrimaryPart.CFrame * CFrame.new(0, 0, ((hitbox.Size.Z/2) + 0.5) * -1)

					hitbox.CFrame = baseCFrame + (velocity * ping)
				else
					hitbox.CFrame = object.PrimaryPart.CFrame * CFrame.new(0, 0, ((hitbox.Size.Z/2) + 0.5) * -1)
				end	
			elseif object:IsA("Part")  then
				hitbox.CFrame = object.CFrame * CFrame.new(0, 0,((hitbox.Size.Z/2) + 0.5) * -1) 
			else
				warn("no")
				hitbox.CFrame = CFrame.new(math.huge, math.huge, math.huge)
			end

			local parts = workspace:GetPartBoundsInBox(hitbox.CFrame, size)
			for _, part in ipairs(parts) do
				local model = part:FindFirstAncestorOfClass("Model")
				if model and model ~= object and model:FindFirstChildOfClass("Humanoid") then
					hitbox.Color = Color3.fromRGB(0, 255, 0)
					game:GetService("Debris"):AddItem(hitbox, 0.8)
					return model
				end
			end
			game:GetService("Debris"):AddItem(hitbox, 0.6)
			return nil
		end

		returning = CreatePart()

		if returning then
			return returning
		else
			return nil
		end		
	end
end
1 Like

are those parts? dont use parts they are unreliable, use either spatial query api or shape casting / raycasting

the parts are intentional, since its taking inspiration from forsakens hitbox system

delayed as in laggy? how many parts are there in the scene, because you might want to create a different collision group for the parts you want to check for, so you can reduce the amount of parts it needs to check.

it creates 30 hitboxes, and ends if it touches a model with a humanoid

This is common in survival games do this their isn`t really a perfect way to do it.

local adjustedPing = ping + 0.05 -- add small buffer for server-client diff
local predictedPos = velocity * adjustedPing
hitbox.CFrame = baseCFrame + predictedPos

This code still is pretty delayed :broken_heart:

forsaken dont use parts… if it did it would be so much more laggier

im 99 percent sure they use shapecasts due to the way that there is a trail dir

1 Like

Games dont actually use parts, they only use that to display hitboxes to the player lmao

Anyways, if you’re trying to make hitboxes like forsaken, moving the hitboxes a little more in the direction the player is moving should work?

i dont even want to know why you would want to make forsaken hitboxes in the first place, but uh, your choice ig

(they are unreliable as hell)

its something im, and other players are used to.

yeah im pretty sure thats not how the forsaken hitboxes work, use spatial query not parts like the above post says

There is no perfect hitbox system, because of the lag and delay between the clients and the server, that’s just how life works, all Roblox games I played have lag in their hitboxes, and I have faced personally similar issues to yours.