Something as simple as changing factors to sums breaks vector3 calculations

Ok, so basically I am experimenting with toolboxed black holes to learn more about Lua and I’ve been trying to experiment on how I can more so balance the range gain of what the black hole gets when chewing up parts by editing the code a little bit so that the range doesn’t “exponentially” get larger due to the fact that I’m guessing its using mainly the mass of the other parts to gain range but instead of adding it, its multiplying it. This results in a much more larger range gain over time and I would want to reduce that if possible. So I tried doing so by changing the multiplier to a sum and Vector3 ended up erroring out even though I don’t think anything really went wrong. Here is the visual example:

local hole = script.Parent
local childList = {}

local massConstant = 5.8 -- Generally a good value

local mass = 10000 * massConstant

-- This is basically a function that finds all unanchored parts and adds them to childList.
-- Note: This should only be run once for each object
function checkObject(obj)
if (obj ~= hole) and (obj.className == "Part") then
	if (obj.Anchored == false) then
		table.insert(childList, 1, obj)
elseif (obj.className == "Model") or (obj.className == "Hat") or (obj.className == "Tool") or (obj == workspace) then
	local child = obj:GetChildren()
	for x = 1, #child do


print("Black Hole script loaded.")

local n = 0
while true do
if n < #childList then
	n = n + 1
	if n % 800 == 0 then
	n = 1

local child = childList[n]
if (child ~= hole) and (child.className == "Part") and (child.Anchored == false) then
	local relPos = hole.Position - child.Position
	local motivator = child:FindFirstChild("BlackHole Influence")
	if relPos.magnitude * 240 * massConstant < mass then
		if (relPos.magnitude * 320 * massConstant < mass) and (child.Size.z + hole.Size.x >  relPos.magnitude * 2 - 4) then
			mass = mass + child:GetMass()
			script.Parent.Size  = script.Parent.Size +,0.1,0.1)
		mass = mass + 50
		print("Black hole now has a gravitational force of"..mass)
		script.Parent.Sound.Volume = script.Parent.Sound.Volume + 0.01
			table.remove(childList, n)
			n = n - 1 -- This is the reason I need a counter of my own design
			child.CanCollide = false -- I Can assume that things won't escape the black hole.
			if motivator == nil then
				motivator ="BodyPosition")
				motivator.Parent = child
				motivator.Name = "BlackHole Influence"
			motivator.position = hole.Position
			motivator.maxForce =, 1, 1) * mass + child:GetMass() / (relPos.magnitude * massConstant)
	elseif motivator ~= nil then

Anyway, like I stated before, I want the range gain of the influence of the black hole (The range in which parts can be sucked up) reduced. I am not that experienced at Lua, which is why I said I was experimenting with this. If anyone has some clear suggestions on how to fix this, please do tell! Thanks.

1 Like

It would help a lot more if you used the preformatted text tool for putting in your code. I can barely read screenshots on a small laptop screen.