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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 28 Aug 2017 |
| Total Posts: 297 |
|
|
| 23 Oct 2017 11:57 PM |
| Solved the problem. :) Thanks everyone for help. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 24 Oct 2017 12:29 AM |
| https://www.roblox.com/library/1127859877/really-bad-example |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|