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

Why will my PlayerGui only open once?

Asked by 4 years ago
Edited 4 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!

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)

0
you only set it to true, never false. on line 11 and 06 you set the visible to true. perhaps you mean to set line 11 to false instead? Fifkee 2017 — 4y
0
Well when I click the textbutton inside the GUI it would set the GUI to false. OswinFalls 69 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago

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?

0
Maybe. I did double check and the default is set to visible = false. Although it did make make think about something. The button script is LocalScript while this is a regular Script. But there's not a way to get who clicked a textbutton through a regular script as you can't insert a click detector right? OswinFalls 69 — 4y
Ad
Log in to vote
0
Answered by
U_srname 152
4 years ago

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)
0
This didn't work unfortunately. Also I want the GUI to be visible in the second 'else if' statement, just not to give a second clone. Thank you though! OswinFalls 69 — 4y
Log in to vote
0
Answered by 4 years ago

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!

0
There is a hacky way to turn it off/on through the server. If a gui was invisible on my screen but visible on the server, I would do: gui.Visible = false gui.Visible = true. It'll force it to update and will display on the client. PhantomVisual 992 — 4y
0
Oh, okay. That makes sense. Thanks for the advice! OswinFalls 69 — 4y
Log in to vote
0
Answered by
Rynappel 212 Moderation Voter
4 years ago

It doesn't work because you need to close it too.

Answer this question