I have a model which consists of parts with particles, I want to make it appear part by part but since most of the model is particles I cant just simply tween the transparency to do this (that would be ideal) so instead I want to spawn each part right infront of the player according to it’s offset so that it would re-create the model perfectly infront of the player.
Sorry if what i wrote is confusing here is a sort of example of what I want to achieve:
I have 7 parts in a model, I write each part’s cframe offset in an array and then loop through the model and change each part’s cframe to player’s torso * the preset offset which would hopefully recreate the model in its entirety,
i dont know how to explain this better but im going crazy so if anyone can call with me or something so i can show what im trying to do then please
So you are recreating a model relative to the player’s location? I can help with that.
First, we’ll get the model’s CFrame using :GetPivot(). This CFrame would be the player’s Torso. Then, by looping through each part, save the part’s CFrame offset using :ToObjectSpace() on a table.
local offsetData = {}
local modelCFrame = model:GetPivot()
for _, part in pairs(modelCFrame:GetChildren()) do
offsetData[part] = modelCFrame:ToObjectSpace(part:GetPivot())
end
Then, we can place it to the torso using PivotTo()
local torso = character:FindFirstChild("Torso")
for part, position in offsetData do
part:PivotTo(torso.CFrame * position)
task.wait() -- Place any duration here.
end
Note that we’re getting the parts from the original model and placing it onto the Torso.
Thank you for replying to me and I tried the solution you provided and its coming up with the error: ToObjectCFrame is not a valid member of CFrame
I tried modifying your code to fix this but I cant manage, I do think that your solution is exactly what im looking for but its not working. Do you think you could explain it a little further? thanks again
(with a few changes i managed to have the model recreated but it’s really far from the torso)
holy… you are amazing.
you have no IDEA how long i spent trying to figure this out, ive tried a dozen different things and i was so close to giving up with lua entirely because of this.
you saved my life seriously thank you so much
one last thing though do you think its possible to have the model be recreated in a specific order? i named the parts 1 through 7 and before i tried to use a for i,v loop to go through the model
We’d have to edit the offsetData table so that each item contains the object and the object’s offset. Such as {object, objectOffset}.
local offsetData= {}
local modelCFrame = model:GetPivot()
for _, part in pairs(modelCFrame:GetChildren()) do
table.insert(offsetData, {part, modelCFrame:ToObjectSpace(part:GetPivot())})
end
Then, you can use table.sort() to sort each object by their name. Note that this function edits the table and does not return a new table.
table.sort(offsetData, function(a, b)
return tonumber(a[1].Name) < tonumber(b[1].Name)
end)
Then simply use pairs() to the table. And modify some lines.
local torso = character:FindFirstChild("Torso")
for _, partInfo in pairs(offsetData) do
partInfo[1]:PivotTo(torso.CFrame * partInfo[2])
task.wait() -- Place any duration here.
end