I’ve been working with GetPartsInPart() for a hitbox for my weapon. It has been going pretty well till i noticed this issue.
GetPartsInPart() doesn’t detect characters that don’t move and it doesnt print anything out in the output. However if they are moving it detects them. I’ve looked around on the forums but haven’t seen a post addressing this issue.
This is the code I’ve been using to get the detection.
connection = rs.Heartbeat:Connect(function()
local detection = workspace:GetPartsInPart(hitbox, paramas)
for _, hit in pairs(detection) do
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not table.find(debounce, hit.Parent) then
table.insert(debounce, hit.Parent)
print(hit.Parent.Name .. " was hit")
task.wait(0.1)
table.remove(debounce, table.find(debounce, hit.Parent))
end
end
end)
Is it something to do with the extra check?
try printing this:
print(hit.Parent, " ", hit.Parent:FindFirstChild("Humanoid"), " ", table:find(debounce), " ", table.find(hit.Parent))
-- Above line may need to be changed to get the actual items, maybe try Humanoid.Name or something similar
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not table.find(debounce, hit.Parent) then
So I’ve played around with it more and I got curious to see what would happen if it didn’t have any checks and surprisingly didn’t print anything. I’m genuinely so confused.
you should task.spawn the wait so that you dont slow down the loop. Because its causing the loop to wait for .1 seconds and each frame is done in milliseconds, then the wait wont be finished, and no parts is looped in
ok so try printing detection, and you dont really need to check if hit.Parent exists because there will always be a parent. Tell us what you see because i dont really understand whats not hapenning
You might be using include over exclude for the OverlapParams. Also remove the task.wait(), it’s not good to yield Heartbeat frames like that, just use an os.clock() debounce.
local lastTime = 0
rs.Heartbeat:Connect(function()
local timeNow = os.clock()
if timeNow < lastTime then return end; lastTime = timeNow + 0.1
-- code
end)
Try printing the table detection. Try ipairs or nothing over pairs because the latter is meant for Dictionary not array and while it might work it can lead to inconsistent results.
-- use this over ipairs and pairs
for _, hit in detection do
end
Make sure the hitbox has CanQuery to true, disable CanTouch just to see what happens.
I’m not too familiar with it, but doesn’t this line only look for hitboxdirectly in the workspace, not in a subfolder? Shouldn’t you reference the folder like this: local detection = workspace.Debris:GetPartsInPart(hitbox, paramas)