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

Random Teleport Location Gui Help?

Asked by 9 years ago

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

1
I think only two values can be an argument within math.random() alphawolvess 1784 — 9y
0
So what do i use to add multiple values to it? ShadowShocks 42 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.

0
"So math.random(5, 10) will give you a number between one and ten." Edit needed, haha. Goulstem 8144 — 9y
0
Thanks man. Not exactly what i was trying to do but i will try and make it work thanks for the tips! ShadowShocks 42 — 9y
0
It's always those little things. DewnOracle 115 — 9y
Ad

Answer this question