Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my tornado script leave parts hanging in air instead of letting them fall to the ground?

Hi. I am trying to make a Roblox tornado game in the studio, and I made a script that I can't seem to figure out how to get working. The script does pick up things, and it makes them go around the tornado until they reach a certain height, as was intended. But then, it is supposed to let them fall to the ground, but instead, the parts just stay eternally suspended in mid-air. I've tried many different things but I just can't figure it out. Here is the script:

local hole = script.Parent --"hole" is the part that is the tornado
local childList = {}

local massConstant = 5.8

local mass = 32000 * massConstant

function checkObject(obj)
	if (obj ~= hole) and (obj.className == "Part") then
		if (obj.Anchored == false) then
			table.insert(childList, 1, obj)
		end
	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
			checkObject(child[x])
		end
		obj.ChildAdded:connect(checkObject)
	end
end

checkObject(workspace)

print("Tornado script loaded.")

local n = 0
while true do
	if n < #childList then
		n = n + 1
		if n % 800 == 0 then
			wait()
		end
	else
		n = 1
		wait()
	end

	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
			child:BreakJoints()
			if (relPos.magnitude * 320 * massConstant < mass) and (child.Size.z + hole.Size.x >  relPos.magnitude * 2 - 4) then
				mass = mass + child:GetMass()
				table.remove(childList, n)
				n = n - 1
			else
				child.CanCollide = false
				if motivator == nil then
					motivator = Instance.new("BodyPosition")
					motivator.Parent = child
					motivator.Name = "BlackHole Influence"
				end
				motivator.position = hole.Position
				motivator.maxForce = Vector3.new(1, 1, 1) * mass * child:GetMass() / (relPos.magnitude * massConstant)
			end
		elseif motivator ~= nil then
			motivator:Remove()
		end
	end
end

Can anyone help me?

1 answer

Nevermind, I fixed it myself. I simply added:

motivator.Remove()

on the end of the if statement at line 44 and I changed:

child.CanCollide = false

at line 49 to true.

This discussion is preserved as it was. New answers, comments, and votes are closed.