I'm trying to move a textbox to random positions in a frame, and I tried this and no luck.
math.randomseed(os.time()) while wait() do wait(0.1) script.Parent.Position = UDim2.new(math.random(0.068,0.010),0,math.random(0.020,0.01),0) wait(0.1) end
Okay bro, math.random(a,b)
returns an integer
value.
So fix the code like this:
math.randomseed(os.time()) while wait() do wait(0.1) script.Parent.Position = UDim2.new(math.random(10,68)/1000,0,math.random(10,20)/1000,0) wait(0.1) end
If you want a more precise method then:
function rand(a,b,precision) precision = 10^precision local w = 1 local function che(x,weight) return math.floor(x*(10^weight)) == x*(10^weight) end if che(a,w) and che(b,w) then --calculate precision return math.random(a*precision,b*precision)/precision else repeat w = w + 1 until che(a,w) and che(b,w) local p = 10^w a = a * p b = b * p --calculate precision return math.random(a*precision,b*precision)/(precision*p) end end print(rand(1,2,3))
With precision before the dot! HOORAY!
P.S. Using my rand
method is more flexible then hard coding. :winks: