How do you make a part vibrate?

Does that mean that Random.new():NextInteger() is better to use than math.random() or something or are they the same?

The new Random class is generally better for game development, primarily because it gives you control over seeding it and knowing that only your code is using it, guarantee you still don’t get with math.random().

But, your example is not how you want to use it. Random.new() constructs a new random number generator instance, something you certainly don’t want to do for every call to NextInteger or NextNumber. Performance of that would be terrible, in both speed and memory usage, and you would not even be getting the random generator performance of the Random class, because you’d only be pulling one value from each, so your randomness would only be as good as whatever is being used to seed the Random instance, not the generator itself! You’re meant to make one instance and re-use it like this:

local RNG = Random.new(someSeed)
local randomInt = RNG:NextInteger()
local randomFloat = RNG:NextNumber()
local anotherInt = RNG:NextInteger()
...
etc

You should only make one Random.new() call for each independent random number stream you need.

2 Likes

what if I wanted to vibrate it along its orientation?

You adjust the orientation property instead of the CFrame/Position property.