Hi I was trying to script a script where it picks a script from random and makes it visible then waits five seconds then goes invisible. Can you help me?
1 | local frame = script.Parent.MainGui.Websites:GetChildren() |
2 | while true do |
3 | local find = frame [ math.random( 1 ,#frame) ] |
4 | find.Visible = true |
5 | wait( 1 ) |
6 | find.Visible = false |
7 | end |
All of the recent answers are wrong, because if you declare a variable with a math.random() in it, it will output the same number every time. Also, it would be a lot simpler if you simply used #frame to get how many you want, but this means having the frames as the only children of the parent (this doesn't include descendants). So:
1 | local frame = script.Parent.Parent:GetChildren() |
2 | while true do |
3 | local find = frame [ math.random( 1 ,#frame) ] |
4 | find.Visible = true |
5 | wait( 1 ) |
6 | find.Visible = false |
7 | end |
In this case, I had 3 frames and the script was in one of the frames, so it wouldn't stuff it up. I tested in studio, and it worked. - TheDeadlyPanther
1 | lol = website [ math.random( 1 , #website) ] |
2 | while true do [ lol ] .Visible = true |
3 | wait( 5 ) |
4 | [ lol ] .Visible = false end |
1 | local random = website [ math.random( 1 , #Website) ] |
2 | while true do |
3 | (Put the path to the frames here) [ random ] .Visible = true |
4 | wait( 5 ) |
5 | (Put the path to the frames here) [ random ] .Visible = false |
6 | end |
Your original script was actually correct, but for additional randomness, you could add the line
math.randomseed(tick())
to your script.