Unanchored Orbit?

I’m trying to figure out how to make a script that sucks in unanchored parts close to the part the script is in, and makes the parts orbit.

I’ve been trying to figure this out for about an hour, how would I go about doing it?

Tweenservice could do this EASILY,
I made a custom tween

local tweenn
local function tween(Part,Prop,Val,timing,TweenType) 
    local TweenService = game:GetService("TweenService")
    local goal = {}
    goal[Prop] = Val
    if timing then
        local tweenInfo
        if TweenType then
            tweenInfo = TweenInfo.new(timing,Enum.EasingStyle[TweenType])
        else
            tweenInfo = TweenInfo.new(timing)
        end
        tweenn = TweenService:Create(Part, tweenInfo, goal)
    else
           local tweenInfo = TweenInfo.new(5)
        tweenn = TweenService:Create(Part, tweenInfo, goal)
    end
    return tweenn:Play()
end

so basically all you have to do now is get stuff to tween to the center of the part

local tweenn
local function tween(Part,Prop,Val,timing,TweenType) 
    local TweenService = game:GetService("TweenService")
    local goal = {}
    goal[Prop] = Val
    if timing then
        local tweenInfo
        if TweenType then
            tweenInfo = TweenInfo.new(timing,Enum.EasingStyle[TweenType])
        else
            tweenInfo = TweenInfo.new(timing)
        end
        tweenn = TweenService:Create(Part, tweenInfo, goal)
    else
           local tweenInfo = TweenInfo.new(5)
        tweenn = TweenService:Create(Part, tweenInfo, goal)
    end
    return tweenn:Play()
end


local DistanceAway = 10 -- distance before being unable to suck stuff...
local TowardsPart = workspace.Part -- part that gets all the sucked unanchored objects
local folderOfObjects = workspace -- in case you want a certain folder with the unanchored objects..

local function SuckObjects()
    for _, v in pairs(folderOfObjects:GetChildren()) do
        if v:IsA("BasePart") then
            if (v.Position-TowardsPart.Position).Magnitude < DistanceAway then
                tween(v,"Position",TowardsPart.Position,"Quad")
            end
        end
    end
end
SuckObjects()

Basically iterate through a folder / workspace, check to see if their position is a certain amount away before sucking, tween it into the center of the part… Tell me if it doesn’t work since I didn’t test it

1 Like

Incomplete statement at line 21 expected allignment or a function call

There’s just a gap at line 21, are you merging this script with another?

oh you didn’t put – in front of those words

image
new errors

Don’t combine both scripts, just the script below

I didn’t, I just pasted your script into an empty script.

Okay I noticed a few things, I forgot the time and the Anchored statement. Here, it works now… You can set it up in a loop

local tweenn
local function tween(Part,Prop,Val,timing,TweenType) 
	local TweenService = game:GetService("TweenService")
	local goal = {}
	goal[Prop] = Val
	if timing then
		local tweenInfo
		if TweenType then
			tweenInfo = TweenInfo.new(timing,Enum.EasingStyle[TweenType])
		else
			tweenInfo = TweenInfo.new(timing)
		end
		tweenn = TweenService:Create(Part, tweenInfo, goal)
	else
		local tweenInfo = TweenInfo.new(5)
		tweenn = TweenService:Create(Part, tweenInfo, goal)
	end
	return tweenn:Play()
end


local DistanceAway = 100 -- distance before being unable to suck stuff...
local TowardsPart = workspace.AnchoredPart -- part that gets all the sucked unanchored objects
local folderOfObjects = workspace -- in case you want a certain folder with the unanchored objects..

local function SuckObjects()
	for _, v in pairs(folderOfObjects:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Anchored == false then
				if (v.Position-TowardsPart.Position).Magnitude < DistanceAway then
					tween(v,"Position",TowardsPart.Position,5,"Quad")
				else
					print((v.Position-TowardsPart.Position).Magnitude)
				end
			end
		end
	end
end
SuckObjects()
1 Like

image what do i set this to? it says it’s not a valid member of workspace

To whatever the center of attraction is, what you want the other objects to pull towards.

Also I anchored the part as a debug so remove the part that says

v.Anchored = true

because that will stop the part from lerping to the center of attraction, my bad…

is it made to go slow or fast, because i want it to go kind of fast, like a tornado

The “5” in the tween is how fast it goes. Also I just realized the tween forces the objects to anchor otherwise it falls to the ground