Basic random UI position script not working?

I’ve made this extremely simple random UI position script

script.Parent.MouseButton1Click:Connect(function()
	local newX = math.random(0.1, 0.9)
	local newY = math.random(0.1, 0.9)
	script.Parent.Position = UDim2.new(newX, 0, newY, 0)
	print(newX, newY)
end)

But for some reason everytime I click On it It decides to go to the position “(0,0)” an exact position not mentioned inside the math.random, any fix? is this a roblox bug?

I don’t think math.random returns numbers only integers so just do math.random(1,9) then divide that by 10

4 Likes

He is correct

newX=math.random(1,9)/10
2 Likes

math.random only returns integers according to the documentation

Conclusion

You should rather use the Random class which allows you to access it’s NextNumber method.

Example usage

local random: Random = Random.new()
local x: number = random:NextNumber(0, 1) -- 0.2917610161522376

i didnt know that, THANK YOU :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.