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

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

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

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.

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