When the value changes its supposed to destroy the gui and make it not there anymore (not visible). however this did not work. Could anyone tell me why?
local colors = {
Color3.fromRGB(0, 100, 200), -- Blue
Color3.fromRGB(200, 0, 0), -- Red
Color3.fromRGB(0, 200, 0), -- Green
}
script.Parent.TextLabel.BackgroundColor3 = colors[math.random(1, #colors)]
wait(0.5)
end
game.StarterGui.Value.Changed:Connect(function(Destroy)
script.Parent:Destroy()
end)```
Youâre waiting for the gameâs âStarterGuiâ to change instead of the actual UI the player is seeing (player.PlayerGui)
If you want to see if the value changes, you will have to use Instance:GetPropertyChangedSignal. You can also do this with the .Changed but I donât really want to explain it right now.
itâs not a problem with the code, itâs a problem with the lines above the code
example:
you need â)â to close the end, or you get an error which is similar to the one you got
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local value = playerGui:WaitForChild("PlayerGui")
local parent = scipt.Parent
value.Changed:Connect(function(newValue)
print(newValue)
parent:Destroy()
end)