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

How can i set a math.random Vector3 value?

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

2 comments

0

I assume you want the script to teleport either to Part 1 or to Part 2?

0

math.random() does not take matrices. Vector3's are matrices. It will only take numbers.

1 answer

✓ Accepted answer

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

4 comments

0

Yep. All because vectors are matrices and math.random() does not take matrices.

0

Impressive.

0

Its pretty basic ^^

0

Thank you very much, bro! :D

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