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

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

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

2 comments

0

Line 1 runs off the screen, but it's Vector3.new(math.random(-4000,4000),math.random(2000,2000),math.random(-4000,4000))

0

Since there isn't any arithmetic-on-nil error, it's likely that z2 is occasionally <= 0.

1 answer

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.

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