Hello. I’m trying to use GetPartBoundsInRadius to detect collectibles for a magnet powerup i’m trying to make. This works fine for regular parts but when it’s actually collectibles it just refuses to work no matter what i try. Any help?
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
--------------------------------------
task.spawn(function()
while CSettings:GetAttribute("Electron") == true do
print("a")
local Parts = workspace:GetPartBoundsInRadius(Root.Position, 20, Params)
for _, Part in Parts do
print("b")
if Part.Name == "Core" and CollectionService:HasTag(Part.Parent, "Collectible") then
print(Part.Name)
end
end
task.wait()
end
end)
“a” and “b” are printing, but Part.Name just refuses to print no matter what. I have checked multiple times, and all the parts in the Collectible model have CanQuery on, are not unanchored, has a Core part, and the model has the “Collectible” tag in it. I don’t understand why this isn’t working.
my second guess before I investigate the script is that collectables exist on the client, but not the server, and you are doing the getpartsinradius on the server, so can’t see them.
also, whoops, should have read further lol, sorry:
May help find some dumb errors, like if your Core instance is actually named "Core " (trailing spaces) or something like that. It should give you some clue to know which condition in your if statement is failing it. Printing each part that GetPartBoundsInRadius() returns might also reveal that the parts you expect are not even in the radius, like maybe Root.Position is not where you want it, or something like that.
Side note: putting a breakpoint on the if statement line and just looking in the Watch window is the pro way to do this in Studio. Printing things out is fine, and useful in a live server to see it in the logs, but once you get used to breakpoints, it’s much faster for debugging in Studio because you see all the contents of all the variables without having to print them. If you’re spamming the checks though, it might be hard to debug this without adding a bit more code or using a conditional breakpoint.
oh, duh, found your issue, can’t believe I didnt spot that. You forgot to put pairs or ipairs or anything in your for loop:
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
--------------------------------------
task.spawn(function()
while CSettings:GetAttribute("Electron") == true do
print("a")
local Parts = workspace:GetPartBoundsInRadius(Root.Position, 20, Params)
for _, Part in ipairs(Parts) do
print("b")
if Part.Name == "Core" and CollectionService:HasTag(Part.Parent, "Collectible") then
print(Part.Name)
end
end
task.wait()
end
end)
actually nvm I searched it up because I wanted to make sure I wast dumb, (I was), pairs or anything isnt required, just more performant, I never even learned you could just not use them, sorry, this reply is just pointless
Check the collision groups of the collectibles. The OverlapParams object has the CollisionGroup property set to “Default” by default, meaning any BasePart whose collision group that you have set to not collide with the “Default” collision group will be ignored in these operations.