game.StarterGui.ScreenGui.Frame.Visible = true function hide() game.StarterGui.ScreenGui.Frame.Visible = false end local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(Key) if Key == "u" then hide() end end)
It's a script that hides a frame when the "u" key is pressed, but it won't work...
Helpful info: -The script is in workspace (I think that's the problem, cause I don't see any problems in the script itself0
First off, your script should be a LocalScript. These scripts will deal with the client objects such as GUIs and the Player's Mouse. LocalScripts will only work in PlayerGui, Backpack, PlayerScripts, and the Player's Character.
Secondly, you're changing the visibility of a frame in StarterGui, not in PlayerGui. Meaning, if you click to hide it, the GUI will still show on screen until you respawn. To fix this you want to use the PlayerGui, and since you should be using a LocalScript, LocalPlayer should work. LocalPlayer will only work in LocalScripts.
Now to begin fixing your code...
game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true --LocalPlayer is a value of the Players Service, but only for LocalScripts. PlayerGui is a container of GUI objects inside of the Player, this means that any GUI elements added, changed, or removed will change real time with the client. function hide() game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = false end local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(Key) if Key == "u" then hide() end end)
Once again, LocalPlayer will not work inside a regular script. Also, LocalScripts will only work in PlayerScripts, PlayerGui, Backpack, and the Player's Character. So make sure some of these issues get resolved.