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

How can I do an Instance.new and insert an object inside of that part? [Solved]

Asked by 10 years ago

I want to put an explosion inside of a Part that just got made.

p = Instance.new("Part",game.Workspace)
p.Name = "ScriptMadePart"
p.Anchored = true
p.Position = Vector3.new(-22, 11.7, 11)
wait(1)
e = Instance.new("Explosion", game.Workspace.ScriptMadePart)

I do have an Explosion occur. Although, it's in the middle of Game. I want the explosion to become a child of ScriptMadePart. I tried doing the ("Explosion",game.Workspace.ScriptMadePart) but didn't work. I know this must be simple, sorry.

2 answers

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

Since 'p' is your variable assigned to the part you just made, you could set the parent of the explosion to it.

e = Instance.new("Explosion", p)

UPDATE

What you should be concentrating on, concerning the position of the explosion, is the 'Position' property.

For example:

e.Position = p.Position

This will set the position of the explosion to the new part you've created.

0
All I did when I tried what I think you mean was change line 6 to e = Instance.new("Explosion",p) I still got the same exact thing occurring where my explosion is not happening where my part is. alphawolvess 1784 — 10y
0
Updated. Redbullusa 1580 — 10y
0
Oh, Okay. Thank you. alphawolvess 1784 — 10y
Ad
Log in to vote
0
Answered by
Diitto 230 Moderation Voter
10 years ago

Putting an explosions in a part does not make the explosions move to the part position. You have to set Explosion.Position to the part's position.

The correct code is:

local Part = Instance.new("Part",workspace)--// No need for game.Workspace, just use workspace. Tip from me to you ;)

Part.Name='ScriptMadePart';
Part.Anchored=true;
Part.CFrame=CFrame.new(-22,11.7,11);--// Use CFrame, it's more precise.

delay(1,function()--// Spawn a thread in the thread scheduler to make your script more proficient.

    local Explosion=Instance.new('Explosion',Part);
    Explosion.Position=Part.CFrame.p;--// This was what you were missing.

end);

By doing Explosion.Position=Part.CFrame.p( you could also do Explosion.Position=Part.Position ), you set the explosion's position to the part's position.

Answer this question