All I want to do is get a list of all the parts within a certain distance of the player. GetPartBoundsInRadius seems to be what I’m looking for, but the documentation kind of sucks and I’m not sure what I’m doing wrong here. It seems like I’m following the format of the documentation.
Function = RunService.Heartbeat:Connect(function()
local parts = workspace:GetPartBoundsInRadius(char.HumanoidRootPart.Position, 5, {FiltersDescendantInstance={player.Character}, FilterType=Enum.RaycastFilterType.Blacklist})
end)
Well, I’m not sure how GetPartBoundsInRadius works but you can weld a big sphere to the humanoidrootpart of the player with cancollide off and use the Touched event to put the hit.Name in a table. The table will now have everything the sphere has touched. Also, check if the hit.Name is already present in table so it doesn’t get added again. Then with TouchEnded event you can remove hit.Name from the table that means the sphere isn’t touching the part. means its not in the proximity of player.
I’m aware this might not be the best solution but I’m new to scripting so that’s the best I could think of.
it really isnt. Depending on ur situation, .Touched runs every time something touches, meaning it is capable of causing lots of lag. I personally also dont know how to use GetPartBoundsInRadius or InBox properly am still learning, but if you’re looking for optimization, do not use .Touched. I find GetPartBoundsInRadius better for performance
local oOverlapParams = OverlapParams.new()
oOverlapParams.FilterDescendantsInstances = {player.Character}
local parts = workspace:GetPartBoundsInRadius(char.HumanoidRootPart.Position, 5, oOverlapParams)
You can add more overlap parameters to that object as needed.