So, I've been trying to make a script so that players would be teleported to one of the locations given randomly. I'm not to familiar with math.random or anything random in general. Here is something I tried below. If I can figure out how to work this, I'm also going to want to have more locations to be teleported to randomly.
function teleport() script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(math.random(-194.983, 101.68, 1.904, -235.392, 69.082, 41.8)) end script.Parent.MouseButton1Down:connect(teleport)
You're close!
Basically what math.random()
does it it Returns
a random value between the parameters set. So if I write something like,
print(math.random(1,5))
Then the output could be any of these,
1
2
3
4
5
One of the problems with math.random() is it only works with whole numbers. Meaning, if I do something like this,
print(math.random(0.874,2.01))
Then the output could NOT be something like 1.67, because it's not a whole number.
Moving on to your problem. You tried using more than two parameters for your math.random. You can only give two! But you want three random numbers so you would Need to use three math.random()
s. Like this,
function teleport() game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(math.random(-195, 101),math.random( 2, -235),math.random( 69, 42))--I changed all of your script.Parents to local player for simplicity. end script.Parent.MouseButton1Down:connect(teleport)
And that should work. Good Luck!
Also if you'd like "math.random()" to give you decimals, you can simply do this:
x = math.random(0,9) + math.random(0,10)/10
This script will give you numbers with decimals from 0 to 10.