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

How to make Y Axis raise and lower at random?

Asked by
wehosh -1
6 years ago

This is where I'm at and I kinda got tunnel vision when making the rotate model. What would be the most efficient random y axis change?

local model = script.Parent local mainPart = model.Base

--Rotation values (in degrees):

local rotX = 0.1 local rotY = 0.1 local rotZ = 0.1

local delay = 0.01 -- delay between each "Frame"

local mTable = {} local offsetTable = {}

function getListOfParts(inst) for i, v in pairs(inst:GetChildren()) do if v:isA("BasePart") then table.insert(mTable, v) else getListOfParts(v) end end end

getListOfParts(model)

for i, v in pairs(mTable) do offsetTable[i] = mainPart.CFrame:toObjectSpace(mTable[i].CFrame) end

while wait(delay) do mainPart.CFrame = mainPart.CFrame * CFrame.Angles(math.rad(rotX), math.rad(rotY), math.rad(rotZ)) for i, v in pairs(mTable) do v.CFrame = mainPart.CFrame * offsetTable[i] end end

1
Please add code blocks to your question. T0XN 276 — 6y

1 answer

Log in to vote
0
Answered by
yyyyyy09 246 Moderation Voter
6 years ago

I believe what you're looking for is the math function math.random()

You can change your rotY variable to this

local rotY = math.random(0.01,1)

The parameters for math.random is

math.random(MinimumValue,UpperValue)

Also T0XN is correct, please use code blocks next time you make a post, to use codeblocks highlight your code, and press the blue Lua button

Ad

Answer this question