Map Loading Simulation

I want to be able to simulate the loading of a map by tween multiple parts from random positions to the parts that they are supposed to be. My code tries to accomplish that but its only 75% of the way there. My issue is trying to tween the Position and Orientation. I cannot seem to find a way to keep a log of the position of where each part is supposed to be, so when I try loading it in, the parts just move to (0,0,0) and, it doesn’t look pleasant. I’ve tried re-ordering the code, redefining the position and orientation variables, but nothing seems to be working.

When I comment out the position and orientation variables, I get this:
robloxapp-20200905-1551132.wmv (2.5 MB)

When I try adding them in, the code does this:
robloxapp-20200905-1549304.wmv (3.3 MB)

Is there something wrong that I don’t see?

Got it working for you:

Let me know if it’s not what you want.

aaaaaa.rbxl (38.3 KB)

local model = game.Lighting.Model:Clone()
local initialCFrames = {}

--keep track of intial positions/rotation (cframe)
for _, desc in pairs(model:GetDescendants())do
	if desc:IsA("BasePart") or desc:IsA("UnionOperation") then
		initialCFrames[desc] = desc.CFrame
		desc.Anchored = true
		desc.CanCollide = false
	end
end

--spread parts out randomly +- 100 studs in each direction / rotate part ranodomly at a random angle:
for _, desc in pairs(model:GetDescendants())do
	if desc:IsA("BasePart") or desc:IsA("UnionOperation") then
		local offestX, offsetY, offsetZ = math.random(-100,100), math.random(-100,100), math.random(-100,100)
		local angleX, angleY, angleZ = math.rad(math.random(0,360)), math.rad(math.random(0,360)), math.rad(math.random(0,360))
		
		desc.CFrame = CFrame.new(desc.Position.X * offestX, desc.Position.Y * offsetY, desc.Position.Z * offsetZ) * CFrame.Angles(angleX, angleY, angleZ) 
	end
end


wait(3)

--move and load each part into the map:
for i, desc in pairs(model:GetDescendants())do
	if desc:IsA("BasePart") or desc:IsA("UnionOperation") then
		desc.Parent = workspace
		
		local tweenSpeed = 1
		local tween = game:GetService("TweenService"):Create(desc, TweenInfo.new(tweenSpeed), {CFrame = initialCFrames[desc]})
		tween:Play()
		
		--if the index is divisible by 2 (if it's even), wait()
		--this changes how fast the map loads
		--make it a higher number to go faster i.e 3, 5, 10, 20...
		if i % 2 == 0 then
			wait()
		end
	end
end
4 Likes

You got it, thanks for your input.