Change orientation AND position

For a while now I’ve been wondering how I could change the orientation and the location of a Button at the same time.

Why? Well so something like this doesn’t happen:

And here is the script, suggest what I should add so it doesn’t just pair them randomly, what I’m trying to do is to choose a certain pair of Orientation And Position:
local Positions = {

Vector3.new(292.025, 6.502, -255.978),

Vector3.new(117.794, 7.189, -235.464),

Vector3.new(223.797, 6.054, 17.555),

Vector3.new(230.729, 8.047, -144.775)

}

local part = workspace.Button

part.Position = Positions[math.random(1, #Positions)]

part.Parent = workspace

You can use CFrame to change a parts orientation and position at the same time, but I’m not sure if this is what you’re asking?

2 Likes

Use CFrames. They combine position and rotation.

Maybe try that ?

local Positions = {
	"292.025, 6.502, -255.978";
	"117.794, 7.189, -235.464";
	"223.797, 6.054, 17.555";
	"230.729, 8.047, -144.775";
}
local Part = workspace.Button
local Randoms = Positions[math.random(1,#Positions)]

if Randoms == "292.025, 6.502, -255.978" then
	Part.Parent = workspace
	Part.Position = Vector3.new(Randoms)
	Part.Orientation = Vector3.new(0,0,0)--Change it
elseif Randoms == "117.794, 7.189, -235.464" then
	Part.Parent = workspace
	Part.Position = Vector3.new(Randoms)
	Part.Orientation = Vector3.new(0,0,0)--Change it
elseif Randoms == "223.797, 6.054, 17.555" then
	Part.Parent = workspace
	Part.Position = Vector3.new(Randoms)
	Part.Orientation = Vector3.new(0,0,0)--Change it
elseif Randoms == "230.729, 8.047, -144.775" then
	Part.Parent = workspace
	Part.Position = Vector3.new(Randoms)
	Part.Orientation = Vector3.new(0,0,0)--Change it
end

There is another way to do it, is to place a part in the workspace for each position/rotation and simply do

local Positions = {
	"Part1";
	"Part2";
	"Part3";
	"Part4";
}
local Part = workspace.Button
local Randoms = Positions[math.random(1,#Positions)]

Part.Parent = workspace
Part.CFrame = CFrame.new(workspace:FindFirstChild(Randoms.Position))
1 Like