generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Random position teleport not working?

Previous Thread :: Next Thread 
Aeroprop is not online. Aeroprop
Joined: 28 Aug 2017
Total Posts: 297
23 Oct 2017 11:37 PM
function Click()

left = {"-23", "-15", "-5", "-2", "6", "12", "15", "21"}
mid = {"2"}
right = {"-25", "-20", "-15", "-7","1", "10", "20", "25", "30", "37", "40"}


math.randomseed(tick())

script.Parent.Parent.Parent.Parent.Character.UpperTorso.CFrame = CFrame.new(math.random(1, #left), math.random(1, #mid), math.random(1, #right))

end

script.Parent.MouseButton1Down:connect(Click)



I want the CFrame to be a random value from each table, X, Y and X coordinates so players have random spawning positions each time when they enter my arena. For some reason it only changes the players position by like a stud or two...
Report Abuse
PhantomVisual is not online. PhantomVisual
Joined: 08 Apr 2011
Total Posts: 2025
23 Oct 2017 11:44 PM
It's suppose to be:

left[math.random(1, #left)]

and for the others too. #table returns the amount of items a table has.

Ex.
t = {1, 0, 3}
print(#t)
print(math.random(1, #t))

>3
>1 or 2 or 3


Report Abuse
Aeroprop is not online. Aeroprop
Joined: 28 Aug 2017
Total Posts: 297
23 Oct 2017 11:45 PM
Ok I think I know the problem... It doesn't get a value it uses the length of the array...? I guess.
Report Abuse
SurKipper is not online. SurKipper
Joined: 25 Dec 2011
Total Posts: 435
23 Oct 2017 11:51 PM
You're passing in a number;
math.random(1, #left).

You SHOULD be passing the table value:

table[ math.random(1, #table) ]

table = {1, 5, 10, 15, 20}

first method:

math.random(1, #table)

output: some random number between 1, and #table

----
second method:

table[math.random(1, #table)]

output: either 1, 5, 10, 15, or 20.

This is because the second method indexes the table at some position 1 through #table. The first method just gives you a number 1 through #table.
Report Abuse
Aeroprop is not online. Aeroprop
Joined: 28 Aug 2017
Total Posts: 297
23 Oct 2017 11:57 PM
Solved the problem. :) Thanks everyone for help.
Report Abuse
Aeroprop is not online. Aeroprop
Joined: 28 Aug 2017
Total Posts: 297
24 Oct 2017 12:12 AM
Actually no.... It moves left and right but forward and back doesn't work at all.... How come?




function Click()


leftright={-21,-15,-10,5 , 15 , 20}
forwardback={-15,-10,-4,1,10,15,23,28,32}


math.randomseed(tick())

script.Parent.Parent.Parent.Parent.Character.UpperTorso.CFrame = CFrame.new(leftright[math.random(1,#leftright)], 10, forwardback[math.random(1,#forwardback)])

print(game.Workspace.Aeroprop.UpperTorso.CFrame)

script.Parent.Parent.Enabled = false


end

script.Parent.MouseButton1Down:connect(Click)
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
24 Oct 2017 12:29 AM
https://www.roblox.com/library/1127859877/really-bad-example
Report Abuse
Aeroprop is not online. Aeroprop
Joined: 28 Aug 2017
Total Posts: 297
24 Oct 2017 12:31 AM
Solved it.... finally.

Roblox engine is just really bad. See I did:


leftright={30,20,10}
forwardback={-15,-10,-4,1,10,15,23,28,32}


math.randomseed(tick())

kek = leftright[math.random(1,#leftright)]
pep = forwardback[math.random(1,#forwardback)]

--problem lies above me

script.Parent.Parent.Parent.Parent.Character.UpperTorso.CFrame = CFrame.new(leftright[kek, 10, pep)



But when you do this, it works perfectly:



leftright={30,20,10}
forwardback={-15,-10,-4,1,10,15,23,28,32}

math.randomseed(tick())

pep = forwardback[math.random(1,#forwardback)]

script.Parent.Parent.Parent.Parent.Character.UpperTorso.CFrame = CFrame.new(leftright[math.random(1,#leftright)], 10, pep)




Or maybe It's not roblox's fault, maybe It's some logic I'm completely unaware of.
Report Abuse
Aeroprop is not online. Aeroprop
Joined: 28 Aug 2017
Total Posts: 297
24 Oct 2017 12:34 AM
Ok sorry spelling mistake: The first example's CFrame should be (kek, 10, pep).

It doesn't work because Roblox can't do two math random ticks apparently..?

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image