Answered by
8 years ago Edited 7 years ago
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:
7 | 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.
1 | local frame = script.Parent.Parent |
2 | local guiButton = frame.Button |
5 | local function closeFrame() |
9 | guiButton.MouseButton 1 Down:Connect(closeFrame) |
As an example, a function that toggles the state of the frame would be this:
1 | local frame = script.Parent.Parent |
2 | local guiButton = frame.Button |
5 | local function toggleFrame() |
6 | frame.Visible = not frame.Visible |
9 | guiButton.MouseButton 1 Down:Connect(toggleFrame) |