Script that updates all screens with text only does 1

I want to update all screens with 3 different messages after 10 secs each and updates every 5 secs via api

It only does 1 screen and then 1 after and it kinds of weird

I tried changing the waits, adding some other things and still no thing

while true do
    local HttpService = game:GetService("HttpService")
    local response1 = HttpService:RequestAsync({
        Url = 'https://pet-thing-simple-wants.techgam.repl.co/1',
        Method = "GET"
    })
    local response2 = HttpService:RequestAsync({
        Url = 'https://pet-thing-simple-wants.techgam.repl.co/2',
        Method = "GET"
    })
    local response3 = HttpService:RequestAsync({
        Url = 'https://pet-thing-simple-wants.techgam.repl.co/3',
        Method = "GET"
    })

    if response1.Success then
        local returnedData1 = HttpService:JSONDecode(response1.Body)
        game:GetService("TestService"):Message("Feteched from API /1: Type: " .. returnedData1.Type .. " Message: " .. returnedData1.Message, script, 18)
        local returnedData2 = HttpService:JSONDecode(response2.Body)
        game:GetService("TestService"):Message("Feteched from API /2: Type: " .. returnedData2.Type .. " Message: " .. returnedData2.Message, script, 20)
        local returnedData3 = HttpService:JSONDecode(response3.Body)
        game:GetService("TestService"):Message("Feteched from API /3: Type: " .. returnedData3.Type .. " Message: " .. returnedData3.Message, script, 22)
        wait()
        for _,v in pairs(script.Parent:GetChildren()) do
            if v.ClassName == "Part" then
                v.SurfaceGui.BG.Type.Text = tostring(returnedData1.Type)
                v.SurfaceGui.BG.Message.Text = tostring(returnedData1.Message)
                wait(10)
                v.SurfaceGui.BG.Type.Text = tostring(returnedData2.Type)
                v.SurfaceGui.BG.Message.Text = tostring(returnedData2.Message)
                wait(10)
                v.SurfaceGui.BG.Type.Text = tostring(returnedData3.Type)
                v.SurfaceGui.BG.Message.Text = tostring(returnedData3.Message)
            end
        end
    end
    wait(10)
end

https://cdn.discordapp.com/attachments/700015253638873169/967280223206903888/RobloxStudioBeta_OpcJCQbq7t.mp4

This is purely because of the waits. Put them inside of a coroutine.

while true do
    local HttpService = game:GetService("HttpService")
    local response1 = HttpService:RequestAsync({
        Url = 'https://pet-thing-simple-wants.techgam.repl.co/1',
        Method = "GET"
    })
    local response2 = HttpService:RequestAsync({
        Url = 'https://pet-thing-simple-wants.techgam.repl.co/2',
        Method = "GET"
    })
    local response3 = HttpService:RequestAsync({
        Url = 'https://pet-thing-simple-wants.techgam.repl.co/3',
        Method = "GET"
    })

    if response1.Success then
        local returnedData1 = HttpService:JSONDecode(response1.Body)
        game:GetService("TestService"):Message("Feteched from API /1: Type: " .. returnedData1.Type .. " Message: " .. returnedData1.Message, script, 18)
        local returnedData2 = HttpService:JSONDecode(response2.Body)
        game:GetService("TestService"):Message("Feteched from API /2: Type: " .. returnedData2.Type .. " Message: " .. returnedData2.Message, script, 20)
        local returnedData3 = HttpService:JSONDecode(response3.Body)
        game:GetService("TestService"):Message("Feteched from API /3: Type: " .. returnedData3.Type .. " Message: " .. returnedData3.Message, script, 22)
        wait()
        for _,v in pairs(script.Parent:GetChildren()) do
            if v.ClassName == "Part" then
                coroutine.resume(coroutine.create(function()
                    v.SurfaceGui.BG.Type.Text = tostring(returnedData1.Type)
                    v.SurfaceGui.BG.Message.Text = tostring(returnedData1.Message)
                    wait(10)
                    v.SurfaceGui.BG.Type.Text = tostring(returnedData2.Type)
                    v.SurfaceGui.BG.Message.Text = tostring(returnedData2.Message)
                    wait(10)
                    v.SurfaceGui.BG.Type.Text = tostring(returnedData3.Type)
                    v.SurfaceGui.BG.Message.Text = tostring(returnedData3.Message)
                end))
            end
        end
    end
    wait(10)
end

I want their to be 10 seconds between the screens saying something different. I want all the screens to be in sync tho.

yes, that is exactly what this does. The coroutine is allowing all three of the screens to do the same action at the same time without delaying the rest of the script.

1 Like

How did I miss an error so basic? Tysm.

Btw, I will mark your response as solution when my friend says it works. He cant post on devofrum but needed help so I kindly posted for him.

I also just noticed this myself,

but you will probably want to increase this wait at the end to around 30 seconds to substitute for what you originally wanted the 20 seconds in the for loop.