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

How to rotate an object when it is spawned in?

Asked by 5 years ago

In my ServerStorage, when you spawn in a model to a certain position, it is rotated a certain way (which is 90 degrees off). It is not clear to me how this would be done. It cannot be as simple as rotating the model from the ServerStorage. It has to be done by a script, or else it won't work in other places that you spawn it. Here is a portion of it.

bg.S.MouseButton1Click:connect(function()
for i, v in pairs(game.Teams['Garage 6']:GetPlayers()) do
if (locked) then return end
locked = true
local vehicleName = player.Name.."Car"
if (not workspace:FindFirstChild(vehicleName)) then
local model = game.ServerStorage.Vehicles:FindFirstChild(vehicles[index][1]):Clone()
model.Name = vehicleName
model.Parent = game.Workspace
model:MakeJoints()
model:MoveTo(Vector3.new(-519.846, 186.25, -88.916))

Any help is appreciated. Thank you.

0
I know it’s a short answer I’m on phone but use cframe. vissequ 105 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago
Edited 2 years ago

Use :SetPrimaryPartCFrame() to position it before parenting it to the workspace. https://developer.roblox.com/api-reference/function/Model/SetPrimaryPartCFrame

CFrame values can both set a position of a part as well as the orientation of it. If your Model has a PrimaryPart, this function will set the CFrame of the PrimaryPart to where ever you choose and then take all the parts in that model and move them based on where the PrimaryPart is.

local Model = workspace.Car
Model.PrimaryPart = Model.Center

local Clone = Model:Clone()
Clone:MakeJoints()

local spawnPosition = CFrame.new(10, 5, 10) * CFrame.Angles(0, math.rad(90), 0)
--CFrame.new is the position
--CFrame.Angles is the orientation
--math.rad converts degrees to radians

Clone:SetPrimaryPartCFrame(spawnPosition)
Clone.Parent = workspace
Ad

Answer this question