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

Random Teleport Location Gui Help?

So, i made this script for my game witch is supposed to teleport the player to a random position with the values i put in when you click teleport on the Gui but for some reason it does not work?

function Click()
script.Parent.Text = "Teleporting"
wait(3)
script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new math.random(-9.8, 5.68, 76.2, -9.8, 5.68, 1.2,-9.8, 5.68, -81.8)
script.Parent.Text = "Disabled"
wait(0.01)
script.Disabled = true
end

script.Parent.MouseButton1Down:connect(Click)

Can anyone help me fix this or tell me what i did wrong?

Thanks

2 comments

1

I think only two values can be an argument within math.random()

0

So what do i use to add multiple values to it?

1 answer

✓ Accepted answer

The people before me are right, the function math.random() can only take two arguments. The fist is the lower limit, the second is the upper limit. So math.random(5, 10) will give you a number between five and ten.

With that in mind, you will need to make a random number for the X, Y, and Z values, then store them in a temp variable.

local torso =  script.Parent.Parent.Parent.Parent.Character.Torso

function Click()
	script.Parent.Text = "Teleporting"
	wait(3)
	x =  math.random(lowerLimit, upperLimit)
	y =  math.random(lowerLimit, upperLimit)
	z =  math.random(lowerLimit, upperLimit)
	torse.CFrame = CFrame.new(x, y, z)
	script.Parent.Text = "Disabled"
	wait(0.01)
	script.Disabled = true
end

script.Parent.MouseButton1Down:connect(Click)

Make sure you replace the lowerLimit and upperLimit with real values. I couldn't understand what your constraints were, as you had nine of them.

3 comments

0

"So math.random(5, 10) will give you a number between one and ten." Edit needed, haha.

0

Thanks man. Not exactly what i was trying to do but i will try and make it work thanks for the tips!

0

It's always those little things.

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