How can I use my while true to only run when a frame is visible

I am trying to make a code run only when the frame is visible. Here is my code:

local key = http:GetAsync("mylink", true)


while script.Parent.Parent.Visible do 
	wait()
	script.Parent.Text = key
end 

when the script becomes visible, the code does not run and I have tested it to make sure it actually works so there must be an issue with the while true, any suggestions on how to fix this?
Note: I am making the frame visible through another script

try this,

local key = http:GetAsync("mylink", true)


script.Parent.Parent.Changed:Connect(function()
while script.Parent.Parent.Visible do 
	wait()
	script.Parent.Text = key
end
end)

Still doesn’t change the text of the label, does the script need to be a local script?

can I know when do you want the while loop to start running ?

I have another script that is controlling my events, when a player enters a valid input, it checks it and if the input is valid, it makes the frame visible. This is when I want the loop to start running.
This is the code that is making the frame visible (note this bit is inside a separate local script)

game.ReplicatedStorage.UpdateFT.OnClientEvent:Connect(function(subcheckTrueFalse)
	us.Visible = true
	if subcheckTrueFalse == true then
		us.TextColor = BrickColor.new("Neon green")
		us.Text = "Success!"
		script.Parent.Frame.Visible = true 
		script.Parent.TeleportBack.Visible = true 
		

is the frame becoming visible ?

yes however the text is remaining “Label” instead of updating to the text of the key variable

can you send the screen short of explorer ?

image
Here is the explorer, the control is what is making the frame visible and the script is what I am trying to make display the correct key when the frame is visible

1 Like

try this script

game.ReplicatedStorage.UpdateFT.OnClientEvent:Connect(function(subcheckTrueFalse)
 if subcheckTrueFalse then
  while script.Parent.Parent.Visible and task.wait() do
	script.Parent.Text = key
  end
 end
end

but the key variable is defined in the script because it is using http service so I can’t put this inside the local script

is that a server script ?
server scripts don’t run if parented to UIs…

could I use an string value instead using a script to define the text, and then change the serverscript in the UI to a local script with a loop showing the string?

yep, that would work

the value for the string value is not updating, here is the code

local http = game:GetService("HttpService")
local key = http:GetAsync("link", true)


while true do 
	wait(5)

script.Parent.Value = key 
end

where is the string parented to ?

replicated storage (character limit

parent the string to workspace or parent the script to SSS because, server scripts run only when it is in SSS or workspace

it now all works but is there anyway to hide the value so exploiters can’t come and access it to see the key

1 Like

if you try to hide the values, local scripts can no longer access it
you can use remote events to send keys but firing remote events every few seconds would increase ping a lot