✓ Accepted answer
You shouldn't be accessing StarterGui. StarterGui is where GUIs are cloned from. You should be accessing the GUIs in the PlayerGui for players to actually see them. Read this article for more info.
You're also connecting your function wrong. This is a correct example:
local function name()
end
name()
instance.EventName:Connect(name)
You should be using a LocalScript if this is in the StarterGui, with the frame, and just access the GUIs from the script's parents instead of finding them how you are now.
local frame = script.Parent.Parent
local guiButton = frame.Button
local function closeFrame()
frame.Visible = false
end
guiButton.MouseButton1Down:Connect(closeFrame)
As an example, a function that toggles the state of the frame would be this:
local frame = script.Parent.Parent
local guiButton = frame.Button
local function toggleFrame()
frame.Visible = not frame.Visible
end
guiButton.MouseButton1Down:Connect(toggleFrame)