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

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

Asked by 4 years ago
Edited 4 years ago

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!

0
You should base the torpedo position off of the model's position, not off of a stationary position. Psudar 882 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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.

Ad

Answer this question