UI Problem for Opening and Closing

I have 2 UI problems:

  1. I can’t open the UI.
  2. I can’t close the UI.

Scripts:
Script for problem 1:

local One = script.Parent.One
local Two = script.Parent.Two
local Three = script.Parent.Three
local Four = script.Parent.Four
local Five = script.Parent.Five
local Six = script.Parent.Six
local Seven = script.Parent.Seven
local Eight = script.Parent.Eight
local Nine = script.Parent.Nine
local Add = script.Parent.Add

-- UI
local ExtInv = game.StarterGui.ExtraInventory

Add.MouseButton1Click:Connect(function()
	ExtInv.Enabled =  true
end)

Problem 2:

local ExtInv = script.Parent
local Close = script.Parent.Close

Close.MouseButton1Click:Connect(function()
	ExtInv.Enabled = false
end)

All help appreciated!

script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Visible -- Frame is the UI you want to show
end)

this code will make the frame visible when you click on the shop and if you click on it again it will become invisible
to infinity

script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible

oups*

When I click on it again it doesn’t work:
robloxapp-20221026-1955545 (1).wmv (200.7 KB)
Sorry I dont know how to post videos.

You are accessing the StarterGui version of your GUI. Once a player joins, the game loads the GUI(s) to the player’s PlayerGui, in which you should be manipulating the UI components.

Problem 1: Make sure you are using this in a LocalScript:

local One = script.Parent.One
local Two = script.Parent.Two
local Three = script.Parent.Three
local Four = script.Parent.Four
local Five = script.Parent.Five
local Six = script.Parent.Six
local Seven = script.Parent.Seven
local Eight = script.Parent.Eight
local Nine = script.Parent.Nine
local Add = script.Parent.Add

-- UI
local ExtInv = game:GetService("Players").LocalPlayer.PlayerGui.ExtraInventory

Add.MouseButton1Click:Connect(function()
	ExtInv.Enabled =  true
end)

Problem 2: I’m pretty sure this isn’t a problem.


Problem 3: I’m quite confused as to why you would need two Scripts that does one thing (one closes UI, other opens UI) when they can be done in a single Script?

The script still won’t work:

local One = script.Parent.One
local Two = script.Parent.Two
local Three = script.Parent.Three
local Four = script.Parent.Four
local Five = script.Parent.Five
local Six = script.Parent.Six
local Seven = script.Parent.Seven
local Eight = script.Parent.Eight
local Nine = script.Parent.Nine
local Add = game:GetService("Players").LocalPlayer.PlayerGui.Inventory.Add

-- UI
local ExtInv = game:GetService("Players").LocalPlayer.PlayerGui.ExtraInventory
local Close = game:GetService("Players").LocalPlayer.PlayerGui.ExtraInventory.Frame.Close

Add.MouseButton1Click:Connect(function()
	ExtInv.Enabled = not ExtInv.Enabled
end)

Close.MouseButton1Click:Connect(function()
	ExtInv.Enabled = false
end)

Do you do your script on a ‘LocalScript’?

What error message are you getting?

Shoukd work on one script:

Activated = false
Add.Activated:Connect(function()
if Activated == false then
Activated = true
ExtInv.Enabled = Activated
elseif Activated == true then
Activated  = false
ExtInv.Enabled = Activated
end
end)

yes it is in a local script in a gui

script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible -- Frame is the UI you want to show
end)

Do that in your script. Just change it to a simple script.

a local script or a normal script?

A normal script not a LocalScript.

Not really a good idea since the bool can be inverted (flipped, like instead of false, its true)

Its also better to use my method so you can add Tween Animations

So something like this: (This Should work on the Client as intended)

StarterGui = game:GetService("StarterGui");
local ExtInv = StarterGui.ExtraInventory.Frame; -- Set this to the Frame inside the ScreenGui

local Items - {
[1] = script.Parent.One;
[2] = script.Parent.Two;
[3] = script.Parent.Three;
[4] = script.Parent.Four;
[5] = script.Parent.Five;
[6] = script.Parent.Six;
[7] = script.Parent.Seven;
[8] = script.Parent.Eight;
[9] = script.Parent.Nine;
Add = script.Parent.Add;
}

Activated = false;

Items.Add.Activated:Connect(function()
if Activated == false then
	ExtInv.Visible =  true
elseif Activated == true then
ExtInv.Visible = false
end)

Does it matter?, it does the same thing as any other. It should work. Its better than using 2 Scripts.

1 Like

Problem 1 Solution: (Put in a Local Script)

local One = script.Parent:WaitForChild("One")
local Two = script.Parent:WaitForChild("Two")
local Three = script.Parent:WaitForChild("Three")
local Four = script.Parent:WaitForChild("Four")
local Five = script.Parent:WaitForChild("Five")
local Six = script.Parent:WaitForChild("Six")
local Seven = script.Parent:WaitForChild("Seven")
local Eight = script.Parent:WaitForChild("Eight")
local Nine = script.Parent:WaitForChild("Nine")
local Add = script.Parent:WaitForChild("Add")

-- UI
local Players = game:GetService("Players")
local ExtInv = Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ExtraInventory")

Add.MouseButton1Click:Connect(function()
	ExtInv.Enabled =  true
end)

Problem 2 Solution: (Local Script)

local ExtInv = script.Parent
local Close = script.Parent:WaitForChild("Close")

Close.MouseButton1Click:Connect(function()
	ExtInv.Enabled = false
end)

With a normal Script object, you are putting more load on the server (as normal Scripts are intended to be used on the server), load that can be done by the client instead. LocalScripts are the way to go, as the server will not need to deal with each players’ GUIs.