Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

4 comments

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.

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

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,...

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.

1 answer

✓ Accepted answer

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.

2 comments

0

And to generate decimals like 0.5 and 1.5 you can use math.random(min,max)/2

0

ah I see tks man

This discussion is preserved as it was. New answers, comments, and votes are closed.