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

How to make a black hole (Something that pulls other objects toward it)?

I have no idea on this one, but I'd like to know if anyone could let me know what force is needed to do so.

1 comment

0

Try bodyforce, I usually use it for moving platforms, but im sure it would work if you scripted something up

1 answer

Here's a script I made that you should put in a part that's at the centre of the black hole, commented so you know what does what:

hole = script.Parent -- A variable, lets us find the centre of the hole easily

function getDescendants(m) -- A relatively complex function, won't explain
    local t = {}
    for _, c in pairs(m:GetChildren()) do
        table.insert(t, c)
        local desc = getDescendants(c)
        for _, d in pairs(desc) do
            table.insert(t, d)
        end
    end
    return t
end

-- add the event here

while true do -- Loop
	for _, part in pairs(getDescendants(game.Workspace)) do -- Do this for every part in Workspace
		if part:IsA("BasePart") then -- are we looking at a part? If so, do inside
			if part:FindFirstChild("BodyPosition") == nil then -- are we not already sucking in this part? we do this to prevent lag
				bp = Instance.new("BodyPosition", part) -- Make a BodyPosition in the part. BodyPosition sucks objects to a position.
				bp.position = hole.Position -- suck to the black hole				
				bp.maxForce = Vector3.new(9001, 9001, 9001) -- pull REALLY hard
			end  -- End if
		elseif part:IsA("ManualWeld") then --is it a weld?
			part:Destroy() -- THEN DESTROY IT
		end -- End if
	end -- End for
	wait(1) -- Wait. If we don't ROBLOX will crash.
end -- End the loop


THIS WILL LAG HARD. It will kill players, and won't take anchored parts. If you want to destroy the parts when they touch the black hole, add this at -- add the event here:

hole.Touched:connect(function(part) -- when something touches the hole
	if not part:IsA("Terrain") then -- is it not a terrain block? Terrain cannot be destroyed for some reason
		part:Destroy() -- DESTROY IT
	end
end) -- end event

If you want to unanchor anchored parts, add part.Anchored = false after if part:FindFirstChild("BodyPosition") == nil then.

Here it is in action.

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