How to rotate model

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I just wanna make randomly generating bed types. But I cannot change the models rotation.

  2. What solutions have you tried so far? Everything on dev forum, it just changes the location of my model.

-- I usually get FullModels location from get piviot
local Model = script.Parent.BedModel
local Red = script.Parent.Red
local RedPosition = Red:GetPivot().Position
local x = RedPosition.X
local y = RedPosition.Y - 1.25
local z = RedPosition.Z

local RandomModel = math.random(1,1)

if RandomModel == 1 then
	FullModel:Destroy()
	wait()
	local NewModel = game.ReplicatedStorage.Bed.Bed1:Clone()
    -- I usually change the rotation of the part with pivot to
	NewModel:SetPrimaryPartCFrame(CFrame.new(x,y,z))
	NewModel.Parent = workspace
end

CFrame stores both location and rotation values, so you can use the same code you currently have, but with rotation on the CFrame. (e.g. CFrame.new(x,y,z) * CFrame.Angles(xr, yr, zr))

2 Likes

Hey there! You could do this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BedInStorage = ReplicatedStorage:WaitForChild("Bed", math.huge):WaitForChild("Bed1", 30)
local Model = script.Parent.BedModel
local Red = script.Parent.Red
local RedPosition = Red:GetPivot().Position
local YIncrement = -1.25

local RandomModel = math.random(1, 2)

if RandomModel == 1 then
    FullModel:Destroy()
    task.wait()
    local NewModel = BedInStorage:Clone()
    NewModel:PivotTo(CFrame.new(NewModel.WorldPivot.Position) * CFrame.Angles(0, YIncrement, 0))
-- Change CFrame.new(NewModel.WorldPivot.Position) to NewModel.PrimaryPart.Position if the model has a primary part. If not, keep it the same.
end


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.