How can I wait for a UI object to become visible in a script and then fire a function?
local button = script.Parent:WaitForChild("Button")
button.Visible = false -- set the button to initially be invisible
local function onVisibilityChanged()
if button.Visible then
print("Button is now visible!")
-- call your function here
end
end
button:GetPropertyChangedSignal("Visible"):Connect(onVisibilityChanged) -- listen for the visibility to change
In this script, we first get a reference to the UI object (in this case, a button) using the WaitForChild method. We then set the Visible property to false to make the button invisible initially.
Next, we define a function onVisibilityChanged that will be called whenever the Visible property of the button changes. In this function, we check if the button is now visible, and if it is, we print a message and call our desired function.
Finally, we use the GetPropertyChangedSignal method to listen for changes to the Visible property of the button, and connect the onVisibilityChanged function to the VisibilityChanged event. This will ensure that the function is only called once the button becomes visible.
U can use the GetPropertyChangedSignal on the UI, and if the Visiblity changes, Then run a code
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.