How do I position some text in a random place?

As said in the title I want to be able to do this, I tried it my self and I thought I could totally do this!
I tried this:

text.Position = UDim2.new(math.random(0.05,0.86),0,math.random(0.05,0.86),0)

the text only appears in the corner of the screen! No where else. So how can I fix this?

As far as I’m aware, math.random only supports integers (unless you pass no arguments, but that is just for 0-1). Instead, you could use the NextNumber method of a Random object returned by Random.new.

text.Position = UDim2.new(math.random(5,86)/100,0,math.random(5,86)/100,0)

math.random doesn’t work with decimals so just try dividing by 100.

text.Position = UDim2.new((math.random(5,86)/100),0,(math.random(5,86)/100),0)

Example:

-- Assuming you have a parent object, such as a Frame
local parent = script.Parent -- Change this to your actual parent object

local randomX = math.random() -- Generates a random number between 0 and 1
local randomY = math.random()

-- Set the position
text.Position = UDim2.new(randomX, 0, randomY, 0)

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