Is there a code that brings back or resurrects a destroyed model?

Is there a code that brings back or resurrects a destroyed model?

local part = Workspace.jingwon123.JeansDarkBlue
part.pants:Destroy()

Once you call :Destroy() on an instance it gets removed completely - the object goes away, all of its children go away, and it gets cleared out from memory.

What you’d need to do instead is parent it somewhere that it can’t be seen anymore, then you can move it back in. Like if this is local, you could parent it to ReplicatedStorage, and then move it back into Workspace once you want it to be seen again. On the server you can use ServerStorage instead. Then as long as you keep a reference to it, you can always move it back in later.

Thank you friend, but it’s so new to me, could you write down the code to bring back the deleted pants? The pants are inside the character.

It’d be something like:

local pants = Workspace.jingwon123.JeansDarkBlue.pants
pants.Parent = game:GetService("ServerStorage") -- Replace this with ReplicatedStorage if you're doing this on the client

-- Later, same script
pants.Parent = Workspace.jingwon123.JeansDarkBlue

I did, but it didn’t work. I’m writing code on Moon Animator

Well, I would prefer parenting the object to nil so it actually disappears from the game and doesn’t lurk in the game files.

I do not know what the trigger is to put the pants back on so I will just make a debounce so after the specified time the pants are put back on automatically.

local objPath = game.Workspace.jingwon123.JeansDarkBlue
local pants = objPath.pants
local timeToWait = 10 -- 10 seconds that will be waited for
pants.Parent = nil -- parents the pants to nil so it is not in the game anymore
task.wait(timeToWait) -- pauses the process for a given time
pants.Parent = objPath -- sets the parent back to your character, putting the pants on

Edit: You will need to put this code into a “Script” in for example the Workspace of the game.

1 Like

why not save the part in replicated storage and clone it, destroy it whenever you need

would definitely also work for sure

It works perfectly. Thank you so much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.