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

Making Gui visible?

Asked by
Spoookd 32
7 years ago

I am trying to get a gui to be visible to players but I can't get the Player's GUI storage or something (PlayerGUI) I tried a couple of ways:

maps = game.Lighting:GetChildren()
LocalPlayer = game.Players.LocalPlayer
guis = LocalPlayer.PlayerGui

while true do
    if game.Players.NumPlayers >= 1 then
        guis.Frame.Visible = true
        guis.Frame.ImageLabel.Visible = false
        guis.Frame.Madeby.Visible = false
    end
end

1 answer

Log in to vote
0
Answered by 7 years ago

Your script

From what you told me, you have this code inside a server script, that's stored in the workspace. These are your first two problems.


First, you're trying to access the LocalPlayer - in a server script. There is no local player in the server, because the server is not a player. To get the LocalPlayer, it must be referenced inside a LocalScript, that's a descendant of either the player's character, or the player (with the exception of ReplicatedFirst, StarterPlayerScripts, and StarterCharacterScripts)


See ReplicatedFirst: http://wiki.roblox.com/index.php?title=API:Class/ReplicatedFirst (I also have a video on ReplicatedFirst here: https://www.youtube.com/watch?v=WxzgO-60XPw)

See StarterPlayerScripts: http://wiki.roblox.com/index.php?title=API:Class/StarterPlayerScripts

See StarterCharacterScripts: http://wiki.roblox.com/index.php?title=API:Class/StarterCharacterScripts


On a lesser - but also relevant note, you're storing your maps inside the Lighting service. You shouldn't do this. Instead, use one of the services created specifically for the purpose of storing objects like ServerStorage or ReplicatedStorage.


See ServerStorage: http://wiki.roblox.com/index.php?title=API:Class/ServerStorage

See ReplicatedStorage: http://wiki.roblox.com/index.php?title=API:Class/ReplicatedStorage

(I also highly recommend looking into the difference between ServerStorage and ReplicatedStorage - it's pretty simple).


Your code


  • WaitForChild

    • First of all, if your LocalScript is in either the ReplicatedFirst storage, or the StarterPlayerScripts storage, you should use WaitForChild on the player to load the PlayerGui - since these containers are known to load before the player does.
  • While loop

    • Second, your while loop. Nowhere in your loop is anything being paused to then be resumed again, so your computer is trying to comprehend infinity - that's a bad idea. You should have a wait() somewhere in the loop to prevent it from crashing, like this:
    while wait() do
        -- code
    end
    
  • If statement

    • There's nothing particularly "wrong" with your if statement, though it's redundant.

Conclusion

Fixing and studying all these problems will make your code work 100% how you intended it to. I'll work on giving an example of your revised code, but until then, hope this helped.

0
Thanks so much this helped me a lot! And I learned a lot more about this stuff. Thanks!! Spoookd 32 — 7y
Ad

Answer this question