Hey everyone! So I am making this topic because I have a question that has always been wanting to be answered by me. I have always wondered how some devs, code there tycoon to where a part (when bought) plays an animation, like it fades in and drops down and builds. Like it looks like it builds itself and it looks cool. I know that the transparency is easy, just use some tweenservice, but I’m still trying to figure out the other way. Anyone know, how to script it like that? Just curious! Thanks!
2 Likes
I’ve used the following as the basis of a map change system on Atomic Bomberman which makes it look like the parts that make up the map fly out as they unload and then fly in to load.
Just change the model
to whatever you want to fly in. To be re-usable it would need to be defined as a function obviously and would need to take the object and positional data to locate the parts/model you wish to load, but should help you get started.
local model = game.ServerStorage.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
I would like to credit the original wrier of this script, but I can’t remember where I found it.
1 Like
ahhh, ok… Thanks I understand now:)))