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

Any idea why this simple math.random() breaks only sometimes???

Asked by 3 years ago

I'm trying to get a random middle point between the base and somewhere far, which is also slightly random.

local bezierStart = workspace.Base.CFrame+Vector3.new(math.random(-4000,4000),math.random(2000,2000),math.random(-4000,4000))
local z1=bezierStart.p.Z/2
local z2=bezierStart.p.Z/5
local z3=math.random(z1,z2)
print(z3)

This works half the time. Refer to https://i.gyazo.com/d6763e26d1a447f9fae83d4dfe8c639f.mp4

any help would be appreciated - thank you

0
Line 1 runs off the screen, but it's Vector3.new(math.random(-4000,4000),math.random(2000,2000),math.random(-4000,4000)) Drak0Master 172 — 3y
0
Since there isn't any arithmetic-on-nil error, it's likely that z2 is occasionally <= 0. Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Your z1 is larger than z2, therefore the randomization doesn't work. You divide z1 by 2 and z2 by 5. The first number in math.random needs to be lower than the other one, so it'll find a number between the lowest to the highest number.

Ad

Answer this question