Need Scripting Assistance

Hello,

I need help to fix my GUI as the script is not functioning properly.
Screenshot 2024-03-02 154122

My aim is to make it so that the gui swaps transparencies every minute to make a lighting effect like on a police car for my new CAD system I am working on.

Any help or advice would be greatly appreciated.

2 Likes

This script is similar to:

while true do
    script.Parent.Reds.Visible = false
    script.Parent.Blues.Visible = true
    -- missing a wait causing it to instantly switch back
    script.Parent.Reds.Visible = true
    script.Parent.Blues.Visible = false
    wait(1) -- just use task.wait(1)... lol
end

I am assuming that you want the objects to be visible for a certain amount of time, too. Don’t forget to add a task.wait(1) at the end!

Also, I recommend using the task library because the functions in it are more efficient to use.

Here is your script.

while true do
    script.Parent.Reds.Visible = true
    script.Parent.Blues.Visible = false
    task.wait(1)
    script.Parent.Reds.Visible = false
    script.Parent.Blues.Visible = true
    task.wait(1)
end

Keep in mind that while true loops can mess with how Roblox handles memory, and your game could get issues from that. Do you understand how people use debounce variables yet?

2 Likes

If you HAVE to use while loops i suggest wrapping it in a coroutine so that it doesnt yield the entire script.

An example:

coroutine.wrap(function()
    script.Parent.Reds.Visible = true
    script.Parent.Blues.Visible = false
    task.wait(1)
    script.Parent.Reds.Visible = false
    script.Parent.Blues.Visible = true
    task.wait(1)
end)()

I believe task.spawn can work a little better. In this case, it’s just a tiny bit easier to write. Also, I don’t know if anything on a coroutine will solve garbage collection issues.