Why will my PlayerGui only open once?
Asked by
5 years ago Edited 5 years ago
Hi there,
I've been trying to script an object for a library that when you click on it, if you have the right requirements, it will bring up a GUI where you can change what your CurrentJob is. It works perfectly the first time, bringing up the GUI, letting me select the job I want to be currently working in, turning the GUI visible = false when I click the selection button, but then when I click the object again nothing happens. It does print "you already have the job selection GUI" and "You should now see the GUI" when I hit it the second time, clearly passing through my second 'if' statement, and there is no error, but for some reason, the GUI remains visible = false. Can anyone explain why it's doing this?
Also not sure if it matters, but one of the buttons inside the GUI triggers a remote event to change my currentjob status which seems to be working fine...
Thanks for your help!
01 | script.Parent.ClickDetector.MouseClick:Connect( function (player) |
02 | if player.Jobs.LibraryPoints.Value ~ = "" and player.PlayerGui:FindFirstChild( "LibraryJobSelection" ) = = nil then |
03 | print ( "you work here, but don't have the GUI selector yet" ) |
04 | script.Parent.LibraryJobSelection:Clone().Parent = player.PlayerGui |
05 | print ( "here's a copy of the job selection GUI" ) |
06 | player.PlayerGui.LibraryJobSelection.Cover.Visible = true |
07 | print ( "You should now see the GUI" ) |
08 | else if player.Jobs.LibraryPoints.Value ~ = "" then |
09 | print ( "you already have the job selection GUI" ) |
10 | print ( "your username is " ..player.Name) |
11 | player.PlayerGui.LibraryJobSelection.Cover.Visible = true |
12 | print ( "You should now see the GUI" ) |
14 | print ( "you do not work for the Library" ) |
EDIT: I think the issue is that I'm going from a regular script to bring up the GUI and check for rank, then the button inside has a local script that switches it off and changes the rank. It does change my rank and hide the GUI though. But when I try to make them both regular scripts, the button can't find who clicked it. Is there a way to make this a regular script and not get an error of player = nil without a click detector? Here's the local button script:
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | local player = game.Players.LocalPlayer |
04 | if player.Jobs.LibraryRank.Value = = "Book Sorter" |
06 | print ( "You have the right rank" ) |
07 | game.ReplicatedStorage.CJBookSorter:FireServer(player) |
08 | print ( "remote event fired" ) |
09 | script.Parent.Parent.Visible = false |
end)