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

InsertService Question [closed]

Asked by 10 years ago

Well, I know that you can do this:

game:GetService("InsertService"):LoadAsset(--asset).Parent = Workspace

But, when I change the parent part to game.Players.Greatgreatgood5.Backpack, it always ends up as a model. Help?

Locked by FearMeIAmLag and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

When you call LoadAsset, all of the parts are grouped into a Model. This is because the asset might contain multiple instances.

You can select the first object inside the model as follows:

game:GetService("InsertService"):LoadAsset(assetId):GetChildren()[1].Parent = Workspace

GetChildren returns a table of the model's children, so GetChildren()[1] gives you the first object in the table.

0
Thanks, Merely! Greatgreatgood5 55 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

The LoadAsset method always puts whatever it loads in a model object. This is because models on ROBLOX can contain many objects at their root, so the LoadAsset method would need to return many things in cases where it loaded many objects if it didn’t put them in a model object.

You can iterate through all the children of the model returned by the LoadAsset method to put them all where you want them to be:

for _, child in next, Game:GetService('InsertService'):LoadAsset(--[[asset]]):GetChildren() do
    child.Parent = Game:GetService('Players').Greatgreatgood5.Backpack
end