How would i make a constant hitbox checking for hits?
A touched event is out of the question. I have a hitbox script but the problem is it only runs once and wouldnt be correct for projectiles.
local HitboxPart = Instance.new("Part")
HitboxPart.CFrame = Character.PrimaryPart.CFrame * Offset
HitboxPart.Anchored = true
HitboxPart.CanCollide = false
HitboxPart.CanTouch = false
HitboxPart.Size = Size
HitboxPart.Parent = workspace
HitboxPart.Color = Color3.new(1, 0, 0.0156863)
HitboxPart.Transparency = 0.5
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
local Hit = workspace:GetPartsInPart(HitboxPart, Params)
local Characters = {}
print(Hit)
for i, v in Hit do
if v.Parent:FindFirstChildOfClass("Humanoid") and not table.find(Characters, v.Parent) then
table.insert(Characters, v.Parent)
end
end
print(Characters)
task.wait(0.1)
HitboxPart:Destroy()
You’ll need to loop your hit detection portion of the script while the projectile exists. It’d probably be a good idea to use the projectile/hitbox’s existence as the condition for the loop and use the Debris service to ensure they’re cleaned up to avoid memory leaks.
You can throttle the loop to only check every quarter of a second or so to reduce the load on the server. But the higher the throttle the less often it will check and thus the less precise the hit detection will be.
How big and how fast are your projectiles moving?
Anything very small or very fast might have issues with the GetPartsInPart using the projectile.
Have you considered raycasting from the projectile for a few studs? Or perhaps from 2 studs behind the projectile to 2 studs in front of the projectile? This might give you a better ‘range’ of the projectile, and if the ray hits the hitbox then count it as a hit.
Forgot what the term was, but basically what you want to do is cast your hitbox on an interval, around 0.1s, and check between where the projectile currently is, and where it was last interval. I’ve got a guide that goes more in depth here.