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

How can i set a math.random Vector3 value?

Asked by 5 years ago

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

0
I assume you want the script to teleport either to Part 1 or to Part 2? BlueGrovyle 278 — 5y
0
math.random() does not take matrices. Vector3's are matrices. It will only take numbers. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
2
Answered by
hellmatic 1523 Moderation Voter
5 years ago
Edited 5 years ago

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)] ) ) ```

0
Yep. All because vectors are matrices and math.random() does not take matrices. DeceptiveCaster 3761 — 5y
0
Impressive. Maginatoc -5 — 5y
0
Its pretty basic ^^ BenjySmb 16 — 5y
0
Thank you very much, bro! :D Carcharionix2000 7 — 5y
Ad

Answer this question