Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Picking a random frame making it visible then invisible?

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?

local frame = script.Parent.MainGui.Websites:GetChildren()
while true do
    local find = frame[math.random(1,#frame)]
    find.Visible = true
    wait(1)
    find.Visible = false
end

4 answers

✓ Accepted answer

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:

local frame = script.Parent.Parent:GetChildren()
while true do
	local find = frame[math.random(1,#frame)]
	find.Visible = true
	wait(1)
	find.Visible = false
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

3 comments

0

didn't work sorry

0

i just edited my code so if you could help me a little for that would be great!

0

No wait I was being dumb and had code that didn't belong! thanks m8

lol = website[math.random(1, #website)] 
while true do [lol].Visible = true 
	wait(5) 
	[lol].Visible = false end

2 comments

0

This will pick the SAME frame each time.

0

It isn't wrong either lol so disregard^

local random = website[math.random(1, #Website)]
while true do
	(Put the path to the frames here)[random].Visible = true
	wait(5)
	(Put the path to the frames here)[random].Visible = false
end

2 comments

0

explain your answer dingus

0

I did in chat dingus

Your original script was actually correct, but for additional randomness, you could add the line

math.randomseed(tick())

to your script.

This discussion is preserved as it was. New answers, comments, and votes are closed.