Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Screen GUI visibility toggle not functioning correctly?

Asked by 3 years ago

I am creating a system which displays your achievements in game with a scrolling frame. It works by simply clicking an imagebutton and it opening the gui. All is well and good, no errors however testing it isn't the greatest so far.

I noticed that when I click the imagebutton the gui does not open. I had a look at the frame for the gui and it told me it was visible in properties? I can't see anything! I can open it in studio using properties but not in game when I click the imagebutton.

Anyway, here is my script:

local gui = game.StarterGui.Achievements.ScrollingFrame

script.Parent.MouseButton1Up:Connect(function()
    if gui.Visible == false then
        gui.Visible = true
    else
        gui.Visible = false
    end
end)
0
Are there any errors in the output? Also would recomend enabling/disabling the ScreenGui (Achievements) than hiding the ScrollingFrame WoTrox 345 — 3y
0
There are no errors. I will also have a look at enabling/disabling. Zertrezai 11 — 3y
0
Enabling/Disabling doesn't appear to change anything apart from what is expected the enable property. However still does not show the gui. Zertrezai 11 — 3y
0
And where is the script? Also, is it a local or a server script? WoTrox 345 — 3y
View all comments (2 more)
0
The script is a local script in the imagebutton which is in a menu gui. Zertrezai 11 — 3y
0
its beause you were trying to change the startergui itself. change the playergui instead, read @MarkedTomato's answer for more description JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

All UI objects in StarterGui get replicated to the player gui located in the player object. (This applies to all services in the explorer that begin with 'Starter')

  1. Insert a LocalScript into StarterPlayerScripts located in StarterPlayer.

  2. write the following code:

local player = game.Players.LocalPlayer -- getting the client
local playerGui = player:WaitForChild("PlayerGui") -- PlayerGui is located in every client's player object
local imageButton = playerGui.ScreenGui.ImageButton -- use playerGui then define the path to imageButton
local scrollFrame = playerGui.ScreenGui.ScrollingFrame -- use playerGui then define the path to scrollingFrame

imageButton.MouseButton1Click:Connect(function() --  I go with mousebutton1click but you can do what you prefer
    if scrollFrame.Visible == false then -- checks whether it's false
        scrollFrame.Visible = true -- if true sets visible to true
    else -- if otherwise
        scrollFrame.Visible = false -- sets visible to false
    end
end)

If it doesn't work or shows an error just reply cause I haven't tested it.

0
re-check line 1 JesseSong 3916 — 3y
0
After a little bit of configuration to the script I managed to get it to work. Thank you! Zertrezai 11 — 3y
Ad

Answer this question