✓ Accepted answer
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
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.
1 comment
Thanks so much this helped me a lot! And I learned a lot more about this stuff. Thanks!!