|
| 26 Nov 2013 04:08 PM |
How can I get math.random to work? I don't know how to use math.random but heres what I have:
function Click()
teles = {"169, 1.145, 404","169, 1.15, 90.8","495, 1.15, 404.08","495, 1.17, 90.8"} game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(math.random(teles)) end
script.Parent.MouseButton1Down:connect(Click)
|
|
|
| Report Abuse |
|
|
| |
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
|
| 26 Nov 2013 04:14 PM |
teles = {"169, 1.145, 404","169, 1.15, 90.8","495, 1.15, 404.08","495, 1.17, 90.8"} script.Parent.MouseButton1Down:connect(function() for _,v in ipairs(teles) do game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(teles[math.random(#teles)]) end end) |
|
|
| Report Abuse |
|
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
|
| 26 Nov 2013 04:16 PM |
teles = {"169, 1.145, 404","169, 1.15, 90.8","495, 1.15, 404.08","495, 1.17, 90.8"} script.Parent.MouseButton1Down:connect(function() for _,v in ipairs(teles) do game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(v[math.random(#teles)]) end end)
brainfart |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2013 04:19 PM |
Got this error
17:18:49.602 - Players.Player1.PlayerGui.Gui.Loadr.LocalScript:4: bad argument #1 to 'new' (Vector3 expected, got string) |
|
|
| Report Abuse |
|
|
| |
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
|
| 26 Nov 2013 04:22 PM |
| Oh, you used strings in the table, when they need to be numbers. Lemme see what i can do. |
|
|
| Report Abuse |
|
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
| |
|
|
| 26 Nov 2013 04:23 PM |
| Okay, yah im not sure what happend |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2013 04:24 PM |
| No it doesnt work still i dont know what I was thinking what I said nvm |
|
|
| Report Abuse |
|
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
|
| 26 Nov 2013 04:27 PM |
Ok, lol, I was confused too.
You made the Coorinates into strings,instead of number values. I seperated them so they wouldn't error out.
teles = {169, 1.145, 404; 169, 1.15, 90.8; 495, 1.15, 404.08; 495, 1.17, 90.8} script.Parent.MouseButton1Down:connect(function() for _,v in ipairs(teles) do game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(v[math.random(#teles)]) end end)
|
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 26 Nov 2013 04:40 PM |
You could try this, but I haven't had any time to test it and my string patterns are a little rusty:
function getValues(str) local x; local y; local z; for n, s in string.gmatch(str,"[^%d,]+" ) do if n==1 then x = s elseif n==2 then y = s elseif n==3 then z = s end end return x, y, z end
function Click()
teles = {"169, 1.145, 404","169, 1.15, 90.8","495, 1.15, 404.08","495, 1.17, 90.8"} game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(getValues(teles[math.random(1, #teles)])); end
script.Parent.MouseButton1Down:connect(Click); |
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 26 Nov 2013 04:42 PM |
Wait, i forgot the tonumber()
function getValues(str) local x; local y; local z; for n, s in string.gmatch(str,"[^%d,]+" ) do local strin = tonumber(s) if n==1 then x = strin elseif n==2 then y = strin elseif n==3 then z = strin end end return x, y, z end
function Click()
teles = {"169, 1.145, 404","169, 1.15, 90.8","495, 1.15, 404.08","495, 1.17, 90.8"} game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(getValues(teles[math.random(1, #teles)])); end
script.Parent.MouseButton1Down:connect(Click); |
|
|
| Report Abuse |
|
|