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?
The code is pretty big. I call the Hitbox function in my Dash() function here:
local function Dash(signal: string, animation)
animation:GetMarkerReachedSignal(signal):Connect(function()
delay(0.5, function()
local LV = Instance.new("LinearVelocity")
LV.Attachment0 = hrp.RootAttachment
LV.MaxForce = 100000
LV.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
LV.VectorVelocity = Vector3.new(0, 0, -75)
LV.Parent = hrp
delay(0.1, function()
Hitbox()
end)
game.Debris:AddItem(LV, 0.1)
end)
div_fist_particle_1.Parent = character["Right Arm"]
div_fist_particle_2.Parent = character["Right Arm"]
game.Debris:AddItem(div_fist_particle_1, 0.8)
game.Debris:AddItem(div_fist_particle_2, 0.8)
end)
end
Ok, I added the workspace:GetPartBoundsInBox(hitbox.CFrame, Vector3.new(5,5,5)) into my code. Now it damages me, but not the enemy.
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.