Math.Random Not working for UDIM2

Hey! So Im making a coin effect and I want coins to appear at random positions on the screen.

if CoinAmount < 17 then
		wait(5)
		for i =1, CoinAmount do
			local coinImg = script.Parent.CoinImg:Clone()
			coinImg.Parent = script.Parent
			coinImg.Name = tostring(i)
			local yPos = math.random(0.200,0.700)
			local xPos =math.random(0.200,0.700)
			coinImg.Position = UDim2.new(xPos,0,yPos,0)
			print("X POS: " ..xPos)
			print(i)
			wait(math.random(0.37,0.77))
			
		end
	end

This is the code I have but the “math.Random” Isnt working. It just keeps showing up as zero. What should I do?

math.random() only returns integers, unless you call it without any arguments, in which case it’ll return a decimal value between 0 and 1 inclusively.

https://developer.roblox.com/en-us/api-reference/lua-docs/math

1 Like

Math.Random only returns and accepts integers, instead of

math.random(0.200,0.700)

Try

(math.random(2,7) / 10)
2 Likes

That could work, but if more detail is needed, this can also be used:

(math.random(200,700)/1000)
1 Like