GetPartBoundsInRadius() REFUSING to work no matter what

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.


1 Like

Do the collectables have CanQuery off? https://create.roblox.com/docs/reference/engine/classes/BasePart#CanQuery
It will make it so get parts in bounds, raycasts, etc, won’t work. If it’s enabled, I’ll look at the script again, but thats my first guess on the issue.

1 Like

Nope, they have it on, i’ve checked multiple times.

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:

have CanQuery on

Consider just replacing print("b") with something a bit more useful like:

print(part.Name, part.Name=="Core", CollectionService:HasTag(part.Parent, "Collectible"))

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.

1 Like

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

2 Likes

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.

1 Like

Thanks, but that didn’t seem to fix it. It does indeed have CollisionGroup set as Default.

Ok yeah that was the issue, thanks. Not to mention i had this code for the collectibles, no wonder it wouldn’t work:

    for _, Obj in ipairs(self._Model:GetChildren()) do
        if Obj:IsA("BasePart") then
            Obj.CanQuery = false
        end
    end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.