Gui not destroying?

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)```
1 Like

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.

1 Like

i changed the game.StarterGui to game.player.PlayerGui but it still didint work

when i said “player” i meant the actual player instance (didn’t explain that properly sorry)
terrible grammar moment

then again, the UI would be parented to the PlayerGui so you would just need to put the UI object
image
idk im really bad at explaining things

instead of this

try this

script.Parent.Value.Changed:Connect(funtion(Destroy)
    script.Parent:Destroy()
end)
1 Like

it gave the errorPlayers.uugnut1.PlayerGui.ABE.LocalScript:14: Expected ')' (to close '(' at line 13), got 'script'

it’s not a problem with the code, it’s a problem with the lines above the code
example:
image
you need ‘)’ to close the end, or you get an error which is similar to the one you got
image

funtion

Slight spelling mistake.

Some of the script appears to be missing.

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)

Where is the LocalScript/Script? I think it must be script.Parent.Parent:Destroy()

1 Like

the code is now

	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

script.Parent.Value.Changed:Connect(function(Destroy)
	script.Parent.Parent:Destroy()
end)

still doesnt work

maybe u can try put print() under the script.parent.Value.Changed to check is it working or not

It turned out that it didnt print, the code to change the value is

game.Workspace.Value.Value = 1

now the problem is the event didn’t fire

1 Like

maybe try

script.Parent.Value.Value.Changed:Connect(function()
        print("fired")
end)

Could the value be changed from a local script?

can i see the workspace so i can see the value and script

image

Also the script that is supposed to change value

local camera = workspace.CurrentCamera
local focus = workspace.Focus
local playBtn = script.Parent
local blue = script.Parent.Parent.Frame
local sound = game.Workspace:FindFirstChild('Sound')
local ButtonSound = game.Workspace:FindFirstChild('BSound')
sound:Play()
repeat
	wait(.1)
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

camera.CFrame = focus.CFrame

local function onPlay()
	ButtonSound:Play()
	camera.CameraType = Enum.CameraType.Custom
	playBtn.Visible = false
	value.Value = (1)
	game.Workspace.Value.Value =  game.Workspace.Value
	workspace.Barrier1.CanCollide = false
	workspace.Barrier2.CanCollide = false
	workspace.Barrier3.CanCollide = false
	workspace.Barrier4.CanCollide = false
	blue.Visible = false
	sound:Stop()
end
playBtn.Activated:Connect(onPlay)