I am trying to create a hitbox system for my game, I have tried using the GetPartBoundsInBox method of hitbox but. It didn’t work.
here is the code:
local function Hitbox(damage)
local hitbox = Instance.new("Part")
hitbox.Anchored = false
hitbox.CanCollide = false
hitbox.CanQuery = false
hitbox.CanTouch = false
hitbox.CFrame = CFrame.new(0, 5, 0)
hitbox.Size = Vector3.new(5, 5, 5)
hitbox.Transparency = 0.5
local weld = Instance.new("Weld")
weld.Part0 = hitbox
weld.Part1 = hrp
weld.C0 = CFrame.new(0, 0, 4)
weld.Parent = hitbox
hitbox.Position = hrp.Position
hitbox.Parent = character
local parts = workspace:GetPartBoundsInBox(CFrame.new(0, 5, 0), Vector3.new(5, 5, 5))
local hitCharacters = {}
for i,part in pairs(parts) do
if part.Parent:FindFirstChildOfClass("Humanoid") and not table.find(hitCharacters, part.Parent) then
table.insert(hitCharacters, part.Parent)
part.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(30)
end
end
game.Debris:AddItem(hitbox, 0.5)
end
That’s because the HitBox position you’re specifying in GetPartsBoundsInBox is not the accurate position. You’re welding the hitbox to the character, meaning it moves, so thus you need to reflect that in GetPartBoundsInBox.
So, make sure it’s workspace:GetPartBoundsInBox(hitbox.CFrame, Vector3.new(5,5,5))
Second, you’re only running this method once. Can I see the whole code here?
Well, that’s something. First, make sure to check that the humanoid isn’t your character’s humanoid. Second, print out the results of GetPartBoundsInBox so you can see what’s being found.