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

Is there a way I can make a model spawn where I want it to spawn?

Asked by 9 years ago

I have a script where the script clones a boat from lighting and puts it in workspace when the correct dialog choice is selected. When the boat is cloned it spawns in the middle of the map.

Is there any way I can make it spawn at a certain location?

2 answers

Log in to vote
0
Answered by 9 years ago

Yes, you can just clone it and then move the whole model using the Moveto().

For more information look at the API documentation. API:Class/Model

0
Thanks! alphaboy299 15 — 9y
0
Welcome buoyantair 123 — 9y
0
hmm.. when use that it errors and says"unable to cast double to vector alphaboy299 15 — 9y
Ad
Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

This is a valid hypothetical script.

Model = script.Parent
Dialog = Model:WaitForChild("Dialog")
    BuyDialogChoice = Dialog:WaitForChild("DialogChoice")

Boat = game.Lighting:WaitForChild("Boat")
SpawnBoat = workspace:WaitForChild("SpawnBoat")
SpawnPos = SpawnBoat.Position

Dialog.DialogChoiceSelected:connect(function(Player, DialogChoice)
    if DialogChoice == BuyDialogChoice then
        -- Check to see if the right DialogChoice is selected
        local newBoat = Boat:Clone()
        newBoat.Parent = workspace
        newBoat:MakeJoints()
        newBoat:MoveTo(SpawnBoat)
    end
end)

Please re-parent your Boat to game.ServerStorage. It's recommended, because that's what it's built for. Storage.

Model = script.Parent
Dialog = Model:WaitForChild("Dialog")
    BuyDialogChoice = Dialog:WaitForChild("DialogChoice")

Boat = game.ServerStorage:WaitForChild("Boat")
SpawnBoat = workspace:WaitForChild("SpawnBoat")
SpawnPos = SpawnBoat.Position

Dialog.DialogChoiceSelected:connect(function(Player, DialogChoice)
    if DialogChoice == BuyDialogChoice then
        -- Check to see if the right DialogChoice is selected
        local newBoat = Boat:Clone()
        newBoat.Parent = workspace
        newBoat:MakeJoints()
        newBoat:MoveTo(SpawnBoat)
    end
end)

If everything is perfect, the whole universe is in harmony, the planets are aligned, the comets are streaking, then this should work. BUT. Not until you set the PrimaryPart of your Boat model!

A PrimaryPart is a BasePart object that gives you the options of using either the :MoveTo() or the :SetPrimaryPartCFrame() method.

To set the PrimaryPart of your Boat model, type this in the command bar:

game.ServerStorage.Boat.PrimaryPart = game.ServerStorage.Boat.Engine
-- You can set it to anything, but it HAS to be inside the "Boat" model

So the Boat model should look like this, with the PrimaryPart property not blank.

Answer this question