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: math.random help

Previous Thread :: Next Thread 
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Jan 2014 06:49 PM
This script is supposed to randomly teleport you to a certain part of the game.

It teleports fine, but the only problem is that it you get teleported to the same location every time.

a = math.random(-50,-40)
c = math.random(-61,-50)

script.Parent.MouseButton1Down:connect(function()
player = script.Parent.Parent.Parent.Parent.Parent
player.Character:MoveTo(Vector3.new(a,38.6,c))
game.ServerStorage.LinkedSword:Clone().Parent = player.Backpack
end)

Give me a challenge.
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Jan 2014 06:53 PM
bump

Give me a challenge.
Report Abuse
Oddie9900 is not online. Oddie9900
Joined: 21 Jul 2011
Total Posts: 108
19 Jan 2014 07:01 PM
rekt
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Jan 2014 07:06 PM
help please

Give me a challenge.
Report Abuse
crazypeople203 is not online. crazypeople203
Joined: 09 Sep 2010
Total Posts: 289
19 Jan 2014 07:15 PM
The problem with your math.random is that the variable assigned to the random is being made before the teleport button.

aka you make your random number ONCE, so that's why it's the same thing all the time.

To fix it, all you have to do is move the variable defining inside the function, like this:

script.Parent.MouseButton1Down:connect(function()

a = math.random(-50,-40)
c = math.random(-61,-50)

player = script.Parent.Parent.Parent.Parent.Parent
player.Character:MoveTo(Vector3.new(a,38.6,c))
game.ServerStorage.LinkedSword:Clone().Parent = player.Backpack
end)


All you really needed to do is make the math.random assigned to a variable each time something happens, so it randomly generates the number each time.

math.random is like a one-time thing; it only makes a random number once.
That's why you have to put the math.random inside the loop/function.

Hope this helped!
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Jan 2014 07:19 PM
Trying it now.

Give me a challenge.
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Jan 2014 07:21 PM
Seems to work... thanks!

Give me a challenge.
Report Abuse
crazypeople203 is not online. crazypeople203
Joined: 09 Sep 2010
Total Posts: 289
19 Jan 2014 07:22 PM
You're welcome, and good luck with the rest of whatever you're doing!
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