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 » Scripting Helpers
Home Search
 

Re: Random teleporting

Previous Thread :: Next Thread 
halofire902 is not online. halofire902
Joined: 30 May 2010
Total Posts: 1587
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
halofire902 is not online. halofire902
Joined: 30 May 2010
Total Posts: 1587
26 Nov 2013 04:12 PM
bump
Report Abuse
qrrrq is not online. 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 is not online. 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
halofire902 is not online. halofire902
Joined: 30 May 2010
Total Posts: 1587
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
halofire902 is not online. halofire902
Joined: 30 May 2010
Total Posts: 1587
26 Nov 2013 04:21 PM
Nvm
Report Abuse
qrrrq is not online. 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 is not online. qrrrq
Joined: 27 Jan 2013
Total Posts: 1252
26 Nov 2013 04:23 PM
Oh, lol
Report Abuse
halofire902 is not online. halofire902
Joined: 30 May 2010
Total Posts: 1587
26 Nov 2013 04:23 PM
Okay, yah im not sure what happend
Report Abuse
halofire902 is not online. halofire902
Joined: 30 May 2010
Total Posts: 1587
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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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