So how would I go about getting the original coordinates of where each part in a model (Tree) is, then making the coordinates of where the parts in the tree has ended up back to their original coordinates.
Here is what I have right now, currently I am getting all the coordinates through a for loop, but all the parts in the tree are going to the exact same place not their original place.
for index, v in pairs(Tree:GetDescendants()) do
if not v:IsA("BasePart") then
continue
end
task.spawn(function()
v.CFrame = originCFrame
end)
end
local OriginalPositions = {}
for index, v in pairs(Tree:GetDescendants()) do
if not v:IsA("BasePart") then
OriginalPositions[v] = v.CFrame.Position -- Store the original position in the table
end
end
All this will do is loop through all the descendants of the Tree and add their positions to a table for later use.
If you want to then reset them simply add this to the script:
for part, OriginalPosition in pairs(OriginalPositions) do
task.spawn(function()
part.CFrame = CFrame.new(OriginalPosition) -- Reset the positions
end)
end
Well, isn’t it better storing CFrame in the dictionary instead of Position? For instance, if the treebranch is rotated this will only set the position correctly, but orientation to (0,0,0)
local OriginalCFrames = {}
for _, v in pairs(Tree:GetDescendants()) do
if v:IsA("BasePart") then
OriginalCFrames[v] = v.CFrame -- Store the original CFrame in the table
end
end
for part, OriginalCFrame in pairs(OriginalCFrames) do
task.spawn(function()
part.CFrame = OriginalCFrame -- Reset the CFrame
end)
end