Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with math.random and decimals? [SOLVED]

Asked by
Admin8483 -21
6 years ago
Edited 6 years ago

I am making a screensaver (Yes, I know) and I need it to travel to a random position every five seconds. The problem is, math.random doesn't do decimals, making the script useless.

while true do
    math.randomseed(tick())
    local ab = math.random(0,7)
    local ac = math.random(0,5)
    script.Parent:TweenPosition(UDim2.new(0.ab, 0,0.ac, 0), "InOut", "Quad", 5)
    wait(5)
end

2 answers

Log in to vote
0
Answered by 6 years ago

Try math.random() * some number instead. math.random(number1, number2) only returns integers within the range number1 <= x <= number2. math.random() returns a decimal in the range 0, 1. You can multiply this to get decimals between 0 and the number you multiply it by.

while true do
    math.randomseed(tick())
    local ab = math.random() * 7
    local ac = math.random() * 5
    script.Parent:TweenPosition(UDim2.new(0.ab, 0,0.ac, 0), "InOut", "Quad", 5)
    wait(5)
end
Ad
Log in to vote
0
Answered by
Admin8483 -21
6 years ago

Oops! Sorry! I thought I could never figure this one out but I did! If you think this code has something wrong with it, please let me know!

while true do
    math.randomseed(tick())
    local ad = math.random(0,7)
    local ae = math.random(0,5)
    local ab = ad / 10
    local ac = ae / 10
    script.Parent:TweenPosition(UDim2.new(ac , 0, ac, 0), "InOut", "Quad", 5)
    wait(5.1)
end

Answer this question