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!
script.Parent.ClickDetector.MouseClick:Connect(function(player) if player.Jobs.LibraryPoints.Value ~= "" and player.PlayerGui:FindFirstChild("LibraryJobSelection") == nil then print ("you work here, but don't have the GUI selector yet") script.Parent.LibraryJobSelection:Clone().Parent = player.PlayerGui print ("here's a copy of the job selection GUI") player.PlayerGui.LibraryJobSelection.Cover.Visible = true print ("You should now see the GUI") else if player.Jobs.LibraryPoints.Value ~= "" then print("you already have the job selection GUI") print("your username is "..player.Name) player.PlayerGui.LibraryJobSelection.Cover.Visible = true print ("You should now see the GUI") else print ("you do not work for the Library") end end end)
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:
script.Parent.MouseButton1Click:Connect(function() local player = game.Players.LocalPlayer print (player.Name) if player.Jobs.LibraryRank.Value == "Book Sorter" then print("You have the right rank") game.ReplicatedStorage.CJBookSorter:FireServer(player) print("remote event fired") script.Parent.Parent.Visible = false end
end)
Maybe it's something to do with MouseClickButton1, I reckon that the GUI shows up by default and then won't show up again because the click detector script isn't working. Does this work?
This should work:
script.Parent.ClickDetector.MouseClick:Connect(function(player) if player.Jobs.LibraryPoints.Value ~= "" and player.PlayerGui:FindFirstChild("LibraryJobSelection") == nil then print ("you work here, but don't have the GUI selector yet") script.Parent.LibraryJobSelection:Clone().Parent = player.PlayerGui print ("here's a copy of the job selection GUI") player.PlayerGui.LibraryJobSelection.Cover.Visible = true print ("You should now see the GUI") elseif player.Jobs.LibraryPoints.Value ~= "" then print("you already have the job selection GUI") print("your username is "..player.Name) player.PlayerGui.LibraryJobSelection.Cover.Visible = false print ("You should now see the GUI") else print ("you do not work for the Library") end end)
I figured it out!
I was calling in the local button script for the GUI to turn invisible, but as it was local the global input of turning it visible was overridden by the local command that it should be invisible. I deleted the line of making the GUI invisible in the local button script, and instead had the remote event that also handles the CurrentJob status turn the GUI invisible.
Thank you to everyone who gave me advice and tried to help me solve this issue!