Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Make model spawn in a part even if the part changes position?

Hello So I have a submarine game and in it I have a button that creates a torpedo model(before I had them already attacthed onto my sub) My problem is that when the sub moves to another area the models still spawn where the submarine first spawned. Here is the script.

model = script.Parent.Parent.torpeedo
local backup = model:clone()
model:Destroy()

function onClicked()
 wait(1)


    model = backup:clone()
    model.Parent = game.Workspace
    model:makeJoints()

end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Is is possible to make it so that it spawns near the ship even if it has moved away from its spawn. One option would be to mkae the model spawn in a part but I dont know how to do that. Thanks for your time!

1 comment

0

You should base the torpedo position off of the model's position, not off of a stationary position.

1 answer

✓ Accepted answer

I've changed your code a bit to make it work.

model = script.Parent.Parent.torpeedo
local backup = model:clone()
model:Destroy()

function onClicked()
 wait(1)


    model = backup:clone()
    model.Parent = game.Workspace
    model:makeJoints()
    model:SetPrimaryPartCFrame(torpedoSpawn.CFrame) --add a part to reference were the torpedo should spawn

end
script.Parent.ClickDetector.MouseClick:connect(on

Make sure that the torpedo model has a primary part.

This discussion is preserved as it was. New answers, comments, and votes are closed.