I'm working on a barrage type attack that spawns many hitboxes that do a set amount of damage, but some of the hitboxes simply don't register contact despite them clearly hitting the target. I have a local script calling the server script below repeatedly when the player holds down E. The barrage is supposed to do 60 damage out of a total of 100 default health, but the actual damage numbers vary. The longer I make the delay for the Debris Service the more accurate the hit detection is, but the hitboxes can't just linger there for longer than they appear and it still isn't perfect.
game.ReplicatedStorage.Stand.Events.Barrage.OnServerEvent:Connect(function(player)
-- definitions
db = false
-- hitbox properties
hitBox = Instance.new("Part", workspace)
hitBox.Transparency = 0.5
hitBox.CanCollide = false
hitBox.Massless = true
hitBox.Size = Vector3.new(5,4,5)
hitBox.CFrame = player.Character.LowerTorso.CFrame * CFrame.new(0, 1, -4)
hitBox.TopSurface = 0
hitBox.BottomSurface = 0
-- weld
local weld = Instance.new("Weld")
weld.Part0 = player.Character.HumanoidRootPart
weld.Part1 = hitBox
weld.C0 = CFrame.new(0,0,-3)
weld.Parent = player.Character.HumanoidRootPart
-- Timed Destruction
game:GetService("Debris"):AddItem(hitBox, 0.4)
-- hitBox player interaction
hitBox.Touched:Connect(function(hit)
print("player hit")
local ehum = hit and hit.Parent:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid")
if ehum and ehum ~= player.Character.Humanoid then
if not db then
db = true
ehum:TakeDamage(2)
local walkspeed = hit.Parent.Humanoid.WalkSpeed
hit.Parent.Humanoid.WalkSpeed = 4
wait(0.4)
hit.Parent.Humanoid.WalkSpeed = walkspeed
end
end
end)
end)
If you don't understand what I mean, join the game for yourself: https://www.roblox.com/games/4907040843/Untitled-lemark23-Project?refPageId=4fd71c98-003e-4206-8fa8-d4189f60b3f8
