✓ Accepted answer
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
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.
######If this question helped, leave an upvote I would appreciate it. And if it solved your problem, then hit that accept answer button so you and I both get a reputation point.
2 comments
You didn't call the function hide. Therefor it won't work.
I did on line 11