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?
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?
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
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.
4 comments
Also http://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo
Thanks!
Welcome
hmm.. when use that it errors and says"unable to cast double to vector