I tried to script a button that will open and close a frame but despite the ScreenGUI frames appear on the screen, the button won't function (open and close on click)

local Button = script.Parent.AddAssignment.CloseFrame.CloseButton

Frame = script.Parent.AddAssignment.Frame

function onClick()
	if Frame.Visible == false then
		Frame.Visible = true
	elseif Frame.Visible == true then
		Frame.Visible = false
		
	end
end

Button.MouseButton1Click.connect(onClick)

Note: All the objects above exist in the workspace