Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you create an automatic image slideshow?

Asked by 6 years ago
Edited by User#5423 6 years ago

Hello,

Recently, I have been working on a system which displays background images on my game: https://www.roblox.com/games/225780602/The-Arc

I wanted to create a system that changed between multiple pictures in a loop.

With this in mind, I created a gui: https://cdn.discordapp.com/attachments/356675974928007168/531941278330650634/unknown.png

I then added the script, with a few trial images:

01local back1 = script.Parent
02local back2 = script.Parent.Parent:FindFirstChild("Background2")
03images = {2721116470, 2673015024, 1417408619, 1417402706}
04 
05local one = 1
06local two = 2
07back1.Image = (images[one])
08back2.Image = (images[two])
09 
10local function change1()
11    local succ,err = pcall(function()
12        if one > #images then
13            one = 1
14        else
15            back1.Image = "http://www.roblox.com/asset/?id=" .. (images[one])
View all 57 lines...

Even with trying to use a pcall to fix it. The trial images I selected won't appear correctly. Please play the game to see for yourself.

It would be much appreciated if you could share any suggestions you have to this problem.

0
Edit:- please use [text](url) for links User#5423 17 — 6y
1
why are you using a server script in a GUI User#23365 30 — 6y
0
Good point. I will make it a local script. But it hasn't affected the problem though. Tweakified 117 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Some of your image ids are incorrect. I first copy the id and put it into an image label, Studio will then format and get the correct image id for you. It saves a lot of time for me.

You can then remove the pcalls in the code. Loading a bad image will not stop the code from running.

You can also simplify your code a lot by only using one counter and swapping variables around making the visible image label fade out the next loop.

I would aslo recommend that you use the tween service as you can create a tween of both image labels and run them at the same time giving you the fade in/out effect you want.

Example(As EXpodo1234ALT said you should be using alocal script for client side gui things):-

01local idList = {
02    "2721116470", "2673015010", "1417408615", "1417402635"
03}
04 
05local tweenServ = game:GetService("TweenService")
06 
07local imageLabel1 = script.Parent.ImageLabel1
08local imageLabel2 = script.Parent.ImageLabel2
09 
10-- tween infromation
11local fadeOut = {ImageTransparency  = 1}
12local fadeIn = {ImageTransparency = 0}
13local tweenInfo = TweenInfo.new(4)
14 
15local nextId = 1
View all 45 lines...

I have also uploaded the model here.

Hope this help, comment if you would like me to explain more about the tween service.

0
Works great. Thanks Tweakified 117 — 6y
0
Do you know a tutorial that teaches the basics of the Tween service? Tweakified 117 — 6y
0
Nope sorry. The function Create takes 3 arguments, the instance being tweened, the TweenInfo.new which contains how the tween should be done and a table of that setting are being tweened with the end goal. User#5423 17 — 6y
0
Okay. Thanks Tweakified 117 — 6y
Ad

Answer this question