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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Making a math.random value negative?

Previous Thread :: Next Thread 
icegroudon is online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
22 Jun 2013 09:39 AM
Im making a flying egg using body velocity,and i want it to wait 16 seconds when the first for loop is done,then fly in a different direction. i do this by making the "Number" value negative,but everytime i do it says "Bad argument #1 to "random" (interval is empty),I know is says this because its negative,but,how can i make it negative?
script:
math.randomseed (tick())
script.Speed.Value = math.random (50)
for i = 1,10 do
wait(1)
local Velocity = script.Parent.BodyVelocity
Velocity.velocity = Vector3.new (math.random(script.Speed.Value),math.random(script.Speed.Value),math.random(script.Speed.Value))
print (script.Speed.Value)
script.Number.Value = math.random (4)
if script.Number.Value == 1 then
script.Parent.Sound2:play()
else
script.Parent.Sound:play()

end
end
script.Parent.BodyVelocity.velocity = Vector3.new (0,0,0)
wait(16)
math.randomseed (tick())
script.Speed.Value = -50 - math.random(10)
for i = 1,10 do
wait(1)
local Velocity = script.Parent.BodyVelocity
Velocity.velocity = Vector3.new (math.random(script.Speed.Value),math.random(script.Speed.Value),math.random(script.Speed.Value))
print (script.Speed.Value)
script.Number.Value = math.random (4)
if script.Number.Value == 1 then
script.Parent.Sound2:play()
else
script.Parent.Sound:play()

end
end
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
22 Jun 2013 09:41 AM
math.random(-50,-40)
You can use negative numbers just like you can positive.
Report Abuse
TrueSoulWolf is not online. TrueSoulWolf
Joined: 02 Apr 2011
Total Posts: 460
22 Jun 2013 09:52 AM
And if you couldn't, you could've just done

value = 0 - value

To change it to negative before you use it.
Report Abuse
icegroudon is online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
23 Jun 2013 10:23 AM
Blue,You cant,Thats what i tried already,but it only wants positive intergers for some reason...
True,i Tried also...
Sorry for my accidental arrogance,if there is any here...
Report Abuse
doneyes is online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Jun 2013 10:45 AM
or multiply it by -1
Report Abuse
crazyman32 is online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
23 Jun 2013 11:38 AM
There's a ton of ways to do it

local x0 = -math.random(10, 40)
local x1 = math.random(10, 40)*-1
local x2 = math.random(-40, -10)
local x3 = -(10+(math.random()*30))
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