Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a script that deletes the model but keeps the children? [closed]

Asked by
Troevan -8
5 years ago

So im making a game like the normal elevator. And i am adding a round where "computer" enters the elevator but when the round is over it disapears. I put all the rounds in lighting help pls

Closed as Not Constructive by Leamir, Lugical, and saSlol2436

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
local model = --(Your model)
local children = model:GetChildren()

for i,v in pairs(children) do
    v.Parent = --(Where you want the children to go)
end

model:Destroy()

Use a for i,v in pairs do statement. Basically this just sifts through a table and runs code for every value in the table.

Replace the comments with what is supposed to go there. That script takes all the children of a model and relocates them to wherever you specify. Then after it's done, it deletes the model. If this helped, accept the answer. :)

Ad
Log in to vote
-1
Answered by 5 years ago

I'm not very good with this, but the method I'd use'd be to move the children somewhere else. Then delete the model.

Imagine this: You have a model in Workspace named "Model" with 2 parts named "Part1" and "Part2" respectively. You'd want to do:

game.Workspace.Model.Part1.Parent = game.Workspace game.Workspace.Model.Part2.Parent = game.Workspace game.Workspace.Model:Destroy()