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 » Scripters
Home Search
 

Re: Am I doing something wrong or is math.random() broken

Previous Thread :: Next Thread 
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:08 PM
yeah i know i posted something similar last night but I am really lost here. I don't THINK I'm doing anything wrong but I guess I must be. I am currently trying to make a random GUI pop up on a random part of the screen, here's my script:

game.ReplicatedStorage.ProcessPurchase.OnClientEvent:connect(function(quantity)
for i = 1, quantity do
wait()
local x = game.ReplicatedStorage.casheffect:Clone()
x.Parent = script.Parent.UI
x.Position = UDim2.new(math.random(1,1000) / 1000, 0 , math.random(1,1000) / 1000, 0)
end
end)

Only focus on the math.random() part you dont need to know whats firing it or anything because that all works. Each GUI that it clones goes to the exact same spot on the screen, which I'm pretty sure it shouldn't do.

Also, there is another instance of math.random() not working here (but I am pretty sure I'm doing something wrong in this one):

https://www.youtube.com/watch?v=UxOR1rL_TIY

Anyways, thanks for any feedback!
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 04:09 PM
maybe type this at the beginning of the event:

math.randomseed(tick())


-- Former AKA : luis15232
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:10 PM
I have that at the top, forgot to mention that.
Report Abuse
EvilDonutNoob is not online. EvilDonutNoob
Joined: 26 Jan 2014
Total Posts: 440
03 Mar 2017 04:11 PM
P.G.O

Thank You

Signed,EvilDonutNoob
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 04:11 PM
Put it in the event.

If you're testing in studio tick will always be the same.

-- Former AKA : luis15232
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 04:12 PM
(as far as i know)

-- Former AKA : luis15232
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:14 PM
that doesn't work either I've tried that.
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 04:17 PM
maybe you're changing the position of the wrong thing

-- Former AKA : luis15232
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:18 PM
I'm not.
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 04:19 PM
where is the GUI appearing on the screen?

-- Former AKA : luis15232
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:21 PM
I'm not crazy or a bad scripter by any means.

The directories are all fine how they should be and eveything is working how it should EXCEPT the random positions. This also is not the first time math.random is not random in this game. I am getting really annoyed because math.random isn't something that I should have to worry about. It's really slowing my development process, because these problems haven't happened before to me ever.
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:37 PM
bump
Report Abuse
hasang1 is not online. hasang1
Joined: 09 Nov 2012
Total Posts: 903
03 Mar 2017 04:39 PM
math.random can be confusing at times, try to do a different math.randomseed(), I'd personally suggest a few random numbers multiplying/dividing/adding/etc to time functions
Ex.
math.randomseed(os.time()*42+tick()/13.37)


ROBLOX tagged my signature about how to avoid getting your posts tagged. Handy to know.
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:42 PM
@hasang

sorry but that didnt work either :(
Report Abuse
hasang1 is not online. hasang1
Joined: 09 Nov 2012
Total Posts: 903
03 Mar 2017 04:45 PM
Something is VERY wrong then.
And I can't tell what.



ROBLOX tagged my signature about how to avoid getting your posts tagged. Handy to know.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
03 Mar 2017 04:47 PM
--local script

math.randomseed(tick())
local process = game.ReplicatedStorage:WaitForChild('ProcessPurchase')
local effect = game.ReplicatedStorage:WaitForChid('CashEffect')
local gui = script.Parent
local ui = gui:WaitForChild('UI')

process.OnClientEvent:connect(function(amount)
for i = 1,amount do
local effect = effect:Clone()
effect.Parent = ui
effect.Position = UDim2.new(math.random(1,100)/100,0,math.random(1,100)/100,0)
wait()
end
end)


Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:49 PM
nope
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
03 Mar 2017 04:50 PM
print(gui.Position)

probably because the values are so tiny you barely see a change


Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 04:53 PM
they are relatively large and they all spawn on the same exact position
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 05:11 PM
bump
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
03 Mar 2017 05:13 PM
The first argument which is the number you are starting at is actually optional and not needed if you are starting at 0 or 1.
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 05:14 PM
^ but that doesnt make a difference for what im doing
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 05:50 PM
i asked where the gui appears on screen so i can find a correlation with the random and the position

-- Former AKA : luis15232
Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
03 Mar 2017 05:59 PM
wdym where it appears
Report Abuse
devHoodie is online. devHoodie
Joined: 04 Nov 2008
Total Posts: 30332
03 Mar 2017 06:01 PM
the position of the GUI

-- Former AKA : luis15232
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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