its a server-sided script in a folder in a screen gui that script worked correcty in the studio but didn't work in the game (i know it will not work becuase it's in a screen gui)
-- open main menu local button = script.Parent.Parent.menuopen button.MouseButton1Click:Connect(function(player) script.Parent.Parent.menu.Visible = not script.Parent.Parent.menu.Visible end)
but i can't put it in serverscriptservice or workspace cause i can't get the player to get the screen gui from inside it... so is there a way to get the player without using localplayer ? (it will not work for server scripts) "sorry for weak english" <3
ServerScripts and GUIs do not mix well. I recommend instead using LocalScripts.
I've talked about the differences between Server and Client (Local) quite a lot in my answers, and while I should more than likely type some lengthy explanation about the differences, I'll simplify.
This is a literal snippet from one of my answers
From seeing the comments, this is a Script. It's important to keep in mind that you shouldn't really Studio Test as it's not the best method of testing. I use it just to find and basic typos I have. To really efficiently test, see this link. This will simulate an actual Roblox Game. It will even make it easier to see the server output.
Now with a script, they're not able to get the LocalPlayer. Scripts are mostly server-side, whereas Local Scripts are mostly client-based.
An easy analogy would be you have a neighborhood (server). Each house (client) has one person. If you say "Find the person in your house" to the neighborhood, they're going to have no clue who to find. If you said "Find the person in your house" to a client, they'll pinpoint it exactly. It's also important to note that a Server Script isn't really what you're looking for to change a GUI. Local Scripts are usually the GUI-changers.
When scripting, it's important to know the differences between scripts and what they can do. A local script, for example, is mostly aimed towards the player themselves. A Script (server script) would really be for all players or for world changes. Last is a module script, which I most recently learned about. They're basically functions that you can call in both scripts. They're pretty neat and I love using them.
When you start to learn about FilteringEnabled, you'll really have to use different scripts and understand what they can and can't do. It's not that hard to understand and it can really even be a fun challenge. (It's important to note that most games nowadays are FilteringEnabled, which prevents most hackers from doing they're little hacking stuffs.)
I would definitely study up on FilteringEnabled when you have the chance.
end of snippet
If your goal is to script a GUI, I'd highly recommend going with LocalScripts. Now, if you're still looking for a method on getting a player, I'd recommend using PlayerAdded or MouseClick.
Here's a brief example of the two in use.
local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) --Runs when a player joins the game print(player.Name) end) local clickDetector = Instance.new("ClickDetector") clickDetector.Parent = workspace.Part clickDetector.MouseClick:Connect(function(player) --Runs when a player clicks on the part print(player.Name) end)
If my answer did help you, then please click Accept Answer
An example of this would be making a GUI appear when you click a button. If you put this code in a server Script, it has to tell the server that you pressed the button, and then the server has to tell your client to make the GUI appear. If you used a LocalScript, it could just set the GUI to be visible itself, and completely eliminate the lag time. https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online
MouseButton1Click
event does not pass the player as a parameter. It does not pass anything, in fact.local button = script.Parent.Parent.menuopen button.MouseButton1Click:Connect(function() button.Parent.menu.Visible = not button.Parent.menu.Visible end)
Players.PlayerAdded
, ClickDetector.MouseClick
, or Dialog.DialogChoiceSelected
.