Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

0

Thanks :) Just saying that the game is 1 player per server

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.

0

Done!

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

2 comments

0

IT'S NOT IN PLAYER GUI IT'S IN STARTER GUI

1

"Each time a player spawns, everything in StarterGui is cloned into PlayerGui". :/

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

1 comment

0

Woo teamwork!

This discussion is preserved as it was. New answers, comments, and votes are closed.