Spinner proximity help

Hello!

Basically I’m trying to make a spinner deactivate if the player is a certain distance from it, say 250 studs. I don’t know how to do this other than adding all the spinners to a table and checking the player’s proximity from the spinner which is an issue, the table would hold way too many instances which can be expensive. I then decided to go the physics route and create a 250x250x250 sphere, and use the sphere’s touching parts to find spinners in range. The issue is, if I connect a .Touched event to the sphere, it fires waaaay too many times which is an issue, it causes major frame drops. I decided collision groups might be the best way to go about doing this but I don’t know about a method that returns a table of in-range, in-collision group parts. Any ideas?

GetPartBoundsInRadius returns all the parts in the given radius, it’s not the best, but it’s an option.

You could split the spinners into regions (if that’s feasible), and only perform the magnitude (distance) checking on spinners in a region the player’s character is also in, omitting all of the spinners in other regions.

Will look into that.

That could work too, the spinners are models so I could use GetBoundingBox, though I’m not sure how performant Region3’s are, especially with a large number of spinners. I’ll look into doing that as well though and send an update to both of you.

Something like this

local Spinners = {}
local Radius = 250

local OP = OverlapParams.new()
OP.FilterType = Enum.RaycastFilterType.Whitelist
OP.MaxParts = 1

game:GetService("RunService").Heartbeat:Connect(function()
	--			Get valid parts			--
	local TableOfCharacters = {}
	for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
		table.insert(TableOfCharacters, Player.Character)
	end
	OP.FilterDescendantsInstances = TableOfCharacters
	
	--			Check			--
	for _, Model in pairs(Spinners) do
		if #workspace:GetPartBoundsInRadius(Model:GetPivot().Position, Radius, OP) > 0 then
			print("Spin")
		else
			print("No spin")
		end
	end
end)

Spinners are all models, I think there is a better way to optimize it.