Good evening dev forum peeps, i have a pretty simplish question that im trying to figure out and the gist is that i have a screen gui with a frame in it and inside that frame is an image label with a pretty simple local script which changes the image back and fourth
while true do
script.Parent.Image = "rbxassetid://5816448737"
wait(1)
script.Parent.Image = "rbxassetid://5196722532"
wait(5)
end
The problem here is that the screen gui/frame is not always visible on the screen and i only want the script to run if that said screen gui is actually visible (this is cause it still seems to cycle the images even if the screen gui/frame isnt visible). How would i end up doing this?
You can make use of the :GetPropertyChangedSignal and checking visiblity like so. Depending on your intended behavior place a second check and wait if you want it to reserve the last seen image or revert to one or the other.
local visible_signal = frame:GetPropertyChangedSignal("Visible")
while true do
if not frame.Visible do
visible_signal:Wait()
end
script.Parent.Image = "rbxassetid://5816448737"
wait(1)
script.Parent.Image = "rbxassetid://5196722532"
wait(5)
end
local frame = script.Parent.Parent.Parent
local visible_signal = frame:GetPropertyChangedSignal("Visible")
while true do
if not frame.Visible do
visible_signal:Wait()
end
script.Parent.Image = "rbxassetid://5816448737"
wait(1)
script.Parent.Image = "rbxassetid://5196722532"
wait(5)
end
ah I get my luaisms confused apologies. I think it’s actually just if not frame.Visible then the extra do is not necissary; it creates an extra scope to close with end