Advertisement System

Hey Developers,
I’m currently making this system where a number of adverts get imported from a database I’ve setup, the ID’s of the adverts (decals) then get processed and a Image Label is created in a part.

I then want the advertisements to change every 10 seconds, tweening on and off the part, however as sometimes I could have let’s say up to 30 ads I can’t exactly set variables for every ad.

Any help would be appreciated. :heart:

Do you mind sharing your code with us? So we can take a closer look into the problem.

Well, I don’t really have much to share as sharing the database side of the code is irrelevant to the problem.

Some code for the changing of the images I was using was this:

frame = script.Parent
while true do
wait(10)
frame:TweenPosition(UDim2.new(0, 0, -1, 0), "Out", "Sine", 2)
wait(10)
frame:TweenPosition(UDim2.new(0, 0, -2, 0), "Out", "Sine", 2)
wait(10)
frame:TweenPosition(UDim2.new(0, 0, -3, 0), "Out", "Sine", 2)
wait(10)
frame:TweenPosition(UDim2.new(0, 0, -4, 0), "Out", "Sine", 2)
wait(10)
frame:TweenPosition(UDim2.new(0, 0, -5, 0), "Out", "Sine", 2)
end

However as I mentioned as there could be a unknown amount of adverts on the system at anyone time it’s hard to preset positions and presets if that makes sense.

You might be able to put all the image ids into a big table, then clone the image label each time you want a new ad to show. You could call each specific item in the table for the id and set the image to that specific id

table[1]...table[2]...etc

until you’ve done each specific item, and then repeat. Mainly using a for loop.

just a thought instead of using different variables.

Another side thing, instead of using

while true

which can cause a lot of bugs, try using

while task.wait(10) do

*your code here*

end

as this is more efficient.

Yeah, I tried this and something like creating string values but because of how I’m getting the data from my database using

for i,v in pairs() do

it just duplicates everything twice.