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)
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)
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)
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
IT'S NOT IN PLAYER GUI IT'S IN STARTER GUI
"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
Woo teamwork!
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
Thanks :) Just saying that the game is 1 player per server
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.
Done!