Math.random Help

Hello! I am Domderp999. And, I need some help with math.random. Currently, I am trying to set the new Clouds Instances, “Cover” value, to a random value between 0, and 1. However, it only picks 0 or 1. How can I get it any number in between there? (Sorry for the short Topic)

You will need to use the Random object and use the NextNumber function.

for example, this code makes a random number between 0 and 1

local rand = Random.new()
print(rand:NextNumber(0,1))
2 Likes

wheres the math in math.Random?

1 Like

Its simple, You cant.

“Between” values is only working for the minimum of 0 to any number

But there is a simple solution to that. Put the maximum to 0.9 or other

math.random is not the same as the random object. Random | Documentation - Roblox Creator Hub this is the random object which is more customizable random.

I tried that. Didnt work unfortunately

that is completely false, simply use nextNumber from the random object

I used this:

local TS = game:GetService("TweenService")
local timeToTransform = 5
while true do
	wait(timeToTransform)
	c = Random.new()
	TS:Create(game.Lighting.Clouds,TweenInfo.new(timeToTransform,Enum.EasingStyle.Linear),{Cover = c:NextNumber(0,1)}):Play()
	print(c)
end

but it didn’t work.

what is it printing for c? It might be an issue with the tweening itself

its supposed to be a random Number from 0, 1. To create a random number to tween to

I know but what is it printing for the c value?

I mean what is the value in the output from the print statement? is it printing a random number? is it printing nil?

image
it litteraly prints random

Are you using the beta feature clouds tho?

oh well you setting the c value to the random object you need to print out the Nextnumber value and not the object

that doesnt matter as we are attempting to determine if its an issue with the random

Maybe its roblox’s modified lua languague bug.

what? are you talking about typed lua? That is not being used in this situation

Ok its working now. Thank you. :+1:

Dont forget to mark my answer as the solution. :grin: Im grinding for that regular rank