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

How do I Randomly Rotate a Part?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Rinpix 639 Moderation Voter
4 years ago
Edited 4 years ago

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).

0
Theres actually two arguments of "math.random". In this case, use "math.random(0, 360)". youtubemasterWOW 2741 — 4y
Ad
Log in to vote
0
Answered by
YTGonzo 20
4 years ago
--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
1
that goes in 1 direction since the same random is for X and Y and Z greatneil80 2647 — 4y
0
yeah you could separate the values. YTGonzo 20 — 4y

Answer this question