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

My part only move to the max value not the random value?

Asked by 4 years ago
part = script.Parent


 Rand = math.random(0,10)
while true do
    for i = 1,30 do
        part.CFrame = part.CFrame+Vector3.new(Rand,0,Rand)
        wait()
    end
    wait(2)
        for i = 1,30 do
            part.CFrame = part.CFrame-Vector3.new(Rand,0,Rand)
            wait()
    end
    wait(2)
    end

0
Rand is static. There's your answer. Looking at what you want to do, you could just assign the value of i to X and Z. DeceptiveCaster 3761 — 4y
0
is there a way to choose value from 1-30 but I want it like 0.5,1,1.5,2 not 1,2,3,4 thinhs12 6 — 4y
0
but if i assign the value of i to X and Z. it would not be a random number. It goes from1,2,3,... thinhs12 6 — 4y
0
If you want decimals, you'll have to do math.random(x,y)/z, where z is the number to divide the result by. math.random() does not accept floats, it only takes integers. DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
4 years ago

You assigned Rand as a random from 0 to 10, so the result is random, but the result is already generated and will be the same everytime you use it. If the result is 6, everytime you call the variable Rand it will return 6. You have to assign math.random() on x and a new math.random() on z instead. Or at least put Rand inside the loop so it renews Rand everytime the loop happens.

0
And to generate decimals like 0.5 and 1.5 you can use math.random(min,max)/2 Dfzoz 489 — 4y
0
ah I see tks man thinhs12 6 — 4y
Ad

Answer this question