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
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.