I was working in a teleport script, that sets some times a new Cframe to a model. Until then, this model can only be teleported to 1 region (a Cframe), and I wanted it could be teleported to 2 regions. I tried to use math.random and the main part of the script looks like this:
Cframe.new (Vector3.new (math.random (part1.Position, part2.Position)
But it did not work. After a series of tests I saw that the problem was involving math.random. If, instead, I put Random, for example, it would work. What's wrong with math.random? How do I correct this script
You can't use Vector3 values for math.random
. Since tables assign a position for each value, you can store the parts positions in a table and use math.random to choose one of them:
```
local Positions = {
part1.Position, -- first value of the table (1)
part2.Position -- second value (2)
}
print("First value is", Positions[1]) print("Second value is", Positions[2])
print( "Chose", CFrame.new( Positions[math.random(1, #Positions)] ) ) ```