How can I make this random?

How can I make it so this script randomizes the pic shown every 5 seconds?

local wallpaper = script.Parent

wait(5)

wallpaper.Image = “http://www.roblox.com/asset/?id=8365120131
wait(5)
wallpaper.Image = “http://www.roblox.com/asset/?id=12718259853
wait(5)
wallpaper.Image = “http://www.roblox.com/asset/?id=12718249152
wait(5)
wallpaper.Image = “http://www.roblox.com/asset/?id=10261695535
wait(5)
wallpaper.Image = “http://www.roblox.com/asset/?id=9995947618
wait(5)
wallpaper.Image = “http://www.roblox.com/asset/?id=10261695535
wait(5)
wallpaper.Image = “http://www.roblox.com/asset/?id=9995947618

What you are currently using is very inefficient. I would just do it like this:

local wallpaper = script.Parent
local RandomImage = math.random(1,2,3,4,5,6,7)

local 1 = "http://www.roblox.com/asset/?id=8365120131"

local 2 = "http://www.roblox.com/asset/?id=12718259853"

local 3 = "http://www.roblox.com/asset/?id=12718249152"

local 4 = "http://www.roblox.com/asset/?id=10261695535"

local 5 = "http://www.roblox.com/asset/?id=9995947618"

local 6 = "http://www.roblox.com/asset/?id=10261695535"

local 7 = "http://www.roblox.com/asset/?id=9995947618"

-- Makes a loop that shows a random picture every 5 seconds

while true do
	wallpaper.Image = RandomImage
	task.wait(5) -- Task.Wait is better than wait() as its more accurate to a second than Wait()
end
1 Like
local ids = {
	"8365120131",
	"12718259853",
	"12718249152",
	"10261695535",
	"9995947618",
	"10261695535",
	"9995947618",
}

while true do
	wallpaper.Image = "http://www.roblox.com/asset/?id=" ..ids[math.random(#ids)]
	task.wait(5)
end

I knew it was I just did not know the much better way of doing it

image

This won’t work. That’s the wrong number of arguments for math.random.

Use my solution it’s much more scalable and actually works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.