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

How do i make this script so my inventory goes away the next time you press e?

Asked by 10 years ago

THE OPENING PART IS WORKING Here is the script

--Ignore lines 1 to 9 thats the working part
--Opening part
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)

--Closing part
mouse.KeyDown:connect(function(key)
    if plr.PlayerGui.Inventory.Main.Visible == true then
    if key:lower() == "e" then
        plr.PlayerGui.Inventory.Main.Visible = false
       end  
    end
end)

No output appears

2 answers

Log in to vote
1
Answered by 10 years ago
mouse.KeyDown:connect(function(key)
    if key:lower() == "e" then
        plr.PlayerGui.Inventory.Main.Visible = true
else
        plr.PlayerGui.Inventory.Main.Visible = false
    end
end)
Ad
Log in to vote
0
Answered by 10 years ago

You can also simplify your script by using the "not" keyword.

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

mouse.KeyDown:connect(function(key)
    if key:lower() == "e" then
        plr:WaitForChild("PlayerGui").Inventory.Main.Visible = not plr:WaitForChild("PlayerGui").Inventory.Main.Visible --Sets the visibility of the GUI object to the opposite of what it is already, so false is true and true is false.
    end
end)

Gives you less lines in the script, and saves repeating the KeyDown event twice.

0
Not working :( iluvmaths1123 198 — 10y
0
Edited, should work. Make sure the code is in a Local Script. If it still doesn't work, try placing the local script in the StarterPack, that worked for me. Spongocardo 1991 — 10y
0
I just decided to make a close button iluvmaths1123 198 — 10y

Answer this question