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

How do I Randomly Rotate a Part?

Hello,

How do I make a part randomly rotate.

Iv'e been trying to figure this out for a while yet haven't found any tutorials of scripting help.

Help would be much appreciated.

Thank you

2 answers

This script will randomly rotate the part, and ensure that it doesn't change its position if it happens to be inside another part:

local part = game.Workspace.Part

while true do
	wait(1)
	local X = math.rad(math.random(360))
	local Y = math.rad(math.random(360))
	local Z = math.rad(math.random(360))
	part.CFrame = CFrame.new(part.Position) * CFrame.Angles(X, Y, Z)
end

It's a little complicated, but if you need an explanation, be sure to leave a comment.

This is a more simple script that won't account for when the part is inside of another part:

local part = game.Workspace.Part

while true do
	wait(1)
	local X = math.random(360)
	local Y = math.random(360)
	local Z = math.random(360)
	part.Orientation = Vector3.new(X, Y, Z)
end

math.random(360) returns a random whole number ranging from 1 - 360(inclusive).

1 comment

0

Theres actually two arguments of "math.random". In this case, use "math.random(0, 360)".

--This is pretty simple

local Part = workspace.BPart  -- Get the part
local RadRotation = math.random(10, 50) --Make a random rotation value

Part.Orientation = Vector3.new(RadRotation, RadRotation, RadRotation) --- Rotate the part

2 comments

1

that goes in 1 direction since the same random is for X and Y and Z

0

yeah you could separate the values.

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