While loop doesn't work

Hi guys I am trying to make a loop so that if the parent of the script transparency = 1 then the gui will be not visible but it doesn’t give any errors or work.

local background = script.Parent.BillboardGui.Background
local button = script.Parent

while true do
	if button.Transparency == 1 then
		background.Visible = false
	else
		background.Visible = true
	end
	wait(0.5)
end

The script is in a localscript in the workspace

LocalScripts can’t work if they’re parented inside the workspace, what exactly are you trying to do here? You could just reference it as a regular script & it should work fine

It is a tycoon and when someone buys the button the button turns transparency to 1 so I am trying to check when it turns to 1 so I can make my gui not visible

I made it a normal script and it still doesn’t seem to work

Use a serverscript instead, LocalScripts can’t run inside workspace.

local background = script.Parent.BillboardGui.Background
local button = script.Parent

button:GetPropertyChangedSignal('Transparency'):Connect(function()
    background.Visible = button.Transparency ~= 1
end)

I still need the loop for something else tough why wouldn’t that work,

local player = game.Players.LocalPlayer
local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
local price = script.Parent.Parent.Price
local background = script.Parent.BillboardGui.Background
local button = script.Parent

while true do
	if Stats.Value >= price then
		background.BackgroundColor3 = ('0, 255, 0')
	else
		background.BackgroundColor3 = ('255, 0, 0')
	end
	wait(0.5)
end

BackgroundColor3 is a Color3 value, not a string. Also you can’t access LocalPlayer from serverscripts.
(also i think your trying to check if a number is higher then a instance which isn’t possible)
(and you cant access serverstorage in localscripts i dont know what kind of script this is)

if Stats.Value >= price then
	background.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
else
	background.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
end

Then how can I make a loop as a local script? the colour part I fixed that already thanks tough

I need it to check if the player can afford it so I can make it green or red

This does not work either the gui is still visible even tough the button is not

The client can not access ServerStorage