Model Restoration Function

I’m just wondering if theres any way to restore a model via a script function after removing it.

Here’s a quick example of what I’m trying to go for,

button.MouseButton1Click:Connect(function()
   model:Remove() -- Player left clicks a button, removing the model.
end)

button.MouseButton2Click:Connect(function()
   model:Restore() -- Player right clicks a button, causing the model to come back.
end)

Keep in mind that I’m not trying to make the model disappear or turn invisible, which would look like this:

model.Transparency = 1; model.Transparency = 2

I’m trying to make the model entirely be restored, like refreshed. As far as I’m concerned, theres no function by the name of Restore() or Refresh(), or anything similar.

Let me know if you want me to send my full program in the replies, these are just quick examples^.

Edit: I forgot to mention that I’m not trying to go for a Clone() type function and getting another model off of the ServerStorage.

You can try having a clone of the model.

local restoreModel = model:Clone()
restoreModel.Parent = game.Lighting


button.MouseButton1Click:Connect(function()
   model:Remove()
end)

button.MouseButton2Click:Connect(function()
   restoreModel.Parent = game.Workspace
end)

Not sure if this is what you mean

1 Like

Just edited my original message, sorry lol.

I’m not trying to exactly go for the Clone() function type thing, but if it comes down to it I might have to adapt it in.

@InfiniteBlackPIX’s script is very similar to the script on this link: Instance | Roblox Creator Documentation
Lighting isn’t needed (and has been replaced by ServerStorage or ReplicatedStorage).
It just parents the object to the workspace when you want it and to nil when you don’t.
If you have a group of objects you want to remove and then parent to workspace then you’d either have to put them in a table, name them all with different names, or put a script in each item with a clickdetector.

Could you create a folder in ServerStorage that temporarily holds these models?

local tempValue 
button.MouseButton1Click:Connect(function()
   tempValue = model
   model.Parent = game:GetService("ServerStorage").Temp
end)

button.MouseButton2Click:Connect(function()
   tempValue.Parent = workspace
end)

This script simply re-parents the model and prepares an object value which can be used to recurse the operation.

Looks interesting. Will try it out.