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

How do i make an inventory gui pop up when you press e?

Asked by 10 years ago

Here is the localscript in starterpack.


Player = script.Parent.Parent mouse = Player:GetMouse() function Open(key) key = key:lower() if key == "e" then game.StarterGui.Inventory.Main.Visible = true end end mouse.KeyDown:connect(Open)

3 answers

Log in to vote
2
Answered by 10 years ago

If this is, in fact, a LocalScript, the proper method to get the player is by using game.Players.LocalPlayer.

Another thing is this: The Player's GUIs are NOT in game.StarterGui. They're actually in the Player's PlayerGui, which is inserted on load. Much like StarterPack, StarterGui just holds GUI elements which are later on copied into each Player's PlayerGui.

Here is how you could do what you want, though:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.KeyDown:connect(function(key)
    if key:lower() == "e" then
        plr.PlayerGui.Inventory.Main.Visible = true
    end
end)
0
Thanks :) Just saying that the game is 1 player per server iluvmaths1123 198 — 10y
0
That doesn't change how things work. Even still, the GUIs are copied to the Player's PlayerGui, and changing things in the StarterGui has no immediate effect whatsoever. Please remember to accept one of our answers as the "Accepted Answer" and upvote it. NoahWillCode 370 — 10y
0
Done! iluvmaths1123 198 — 10y
Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

If it's a local script, you can just use game.Players.LocalPlayer instead of parenting up to it.

Anyways, your main problem is that you changed it in StarterGui. StarterGui is what players spawn with, NOT what they are currently seeing. Each time a player spawns, everything in StarterGui is cloned into PlayerGui. Therefore, if you want to affect what a player is currently seeing, you need to make your changes in PlayerGui.

Since you already have the player, you can just do Player.PlayerGui.Inventory.Main.Visible = true

0
IT'S NOT IN PLAYER GUI IT'S IN STARTER GUI iluvmaths1123 198 — 10y
1
"Each time a player spawns, everything in StarterGui is cloned into PlayerGui". :/ Perci1 4988 — 10y
Log in to vote
0
Answered by
ipiano 120
10 years ago

You're really close actually. What you need to do, is change the gui that is specifically in the player. Just change line 7 to

Player.PlayerGui.Inventory.Main.Visible = true
0
Woo teamwork! Perci1 4988 — 10y

Answer this question