My hitbox system hinges on the GetPartBoundsInBox function but it only works half of the time which is not very great for reasons you could guess.
The script itself is very early in it’s production and there is not too much things that could be causing this issue. The CFrame location is correct, The Size is correct, Everything seems to be firing correctly but for some reason it just sometimes does not want to work.
It not working → Forms - Roblox Studio (gyazo.com)
I checked if it had something to do with the CanCollide or CanQuiery properties but it does not seem to change the effect it has in any shape or form. I thought it could be the way it is getting fired but I dont notice anything in paticular in the way it’s fired being an issue otherwise the issue would be completly different.
I will send all relavent code here.
Client side script that fires an event parented to the character.
anim:GetMarkerReachedSignal("Melee"):Once(function(MeleeType:string)
Remote:FireServer(true,"Melee",Mouse.Hit.Position,Heavy)
end)
The server side script parented to the character that runs things from input. Litteraly one line that is relavent.
HitboxModule.RequestHitbox(SelfHum.RootPart.CFrame * CFrame.new(0,0,-2.5),Vector3.new(5,5,5),"Box",SelfChar,true)
The whole hitbox module I am using which seems to be most likely where the issue is.
local Functions = {}
----\/Services\/----
----/\Services/\----
----\/Local Functions\/----
local function RegisterImpact(HitPart:Instance)
print("Hit "..HitPart.Name)
local hithum = HitPart.Parent:FindFirstChildOfClass("Humanoid")
if hithum then
hithum:TakeDamage(5)
end
end
----/\Local Functions/\----
----\/External Functions\/----
function Functions.RequestHitbox(HitboxCFrame:CFrame,HitboxSize:Vector3,HitboxType: "Box" | "Radius",Blacklist:{Instance} | Instance,Visualize:boolean)
--print("Hitbox requested.")
local function HitContacts(Contacts)
for index = 1,#Contacts do
local hit = Contacts[index]
if hit then
print("Contact "..tostring(hit))
if type(Blacklist) == table then
if table.find(Blacklist,hit) then
return
else
RegisterImpact(hit)
end
elseif Blacklist:IsA("Instance") then
if hit:IsDescendantOf(Blacklist) or hit == Blacklist then
return
else
RegisterImpact(hit)
end
end
end
end
end
if HitboxType == "Box" then
local Contacts = game.Workspace:GetPartBoundsInBox(HitboxCFrame,HitboxSize)
HitContacts(Contacts)
if Visualize == true then
local Display = Instance.new("Part")
Display.CFrame = HitboxCFrame
Display.Size = HitboxSize
Display.Shape = Enum.PartType.Block
Display.Material = Enum.Material.ForceField
Display.Anchored = true
Display.CanCollide = false
Display.CanTouch = false
Display.CanQuery = false
Display.Transparency = 0.5
Display.Color = Color3.new(1, 0, 0)
Display.Parent = workspace
game.Debris:addItem(Display,1)
end
elseif HitboxType == "Radius" then
local Contacts = game.Workspace:GetPartBoundsInRadius(HitboxCFrame.Position,HitboxSize.Magnitude/3)
HitContacts(Contacts)
if Visualize == true then
local Display = Instance.new("Part")
Display.Position = HitboxCFrame.Position
Display.Size = HitboxSize
Display.Shape = Enum.PartType.Ball
Display.Material = Enum.Material.ForceField
Display.Anchored = true
Display.CanCollide = false
Display.CanTouch = false
Display.CanQuery = false
Display.Transparency = 0.5
Display.Color = Color3.new(1, 0, 0)
Display.Parent = workspace
game.Debris:addItem(Display,1)
end
end
end
----/\External Functions/\----
return Functions
Any kind of help would be nice. If you need more info then make sure to ask and I will be happy to send more parts of the code or some outputs in the print, ect.