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
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.
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.