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

How do I find a random number between two integers, rather than just picking one or the other?

I'm trying to make a GUI that places Image Labels at (random) various positions across your screen. Although the answer may be simple, I am having a hard time getting the random positions to go through.

Take a look at my code:

local fog = script.Parent.Parent:GetChildren("Fog")

for _,v in pairs (fog) do
	if v.Name == "Fog" then
		v.Position = UDim2.new(math.random(0,1),0,math.random(0,1), 0)
	end
end

I know the problem here is that it will EITHER pick (1) or (0), but what i need it to do is pick a RANDOM number in between (1) and (0).

Please help! Thanks,

1 answer

✓ Accepted answer

If you want decimals from math.random, don't pass any arguments. So instead of

v.Position = UDim2.new(math.random(0,1),0,math.random(0,1), 0)

use

v.Position = UDim2.new(math.random(),0,math.random(), 0)

1 comment

0

wow thanks!

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