Gui script driving me insane

Right now I am having a problem with a gui. For some reason the gui isnt opening the inventory for the project I am making. I will show in parenthesies and arrows where the red line is ( I tried fixing the red line which is probably the issue but cant find what I did wrong) and I will show the tutorial that helped me make the script. Red line is around last lines

-- Player Stuff
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded.Wait()

--Services
local ts = game:GetService("TweenService")
local debris = game:GetService("Debris")
--Gui
local gui = script.Parent
local hotbarF = gui.Hotbar; hotbarF.visible = true
local inventoryF = gui.inventory; inventoryF.visible = false

local s1 = hotbarF.Slot1
local s2 = hotbarF.Slot2
local s3 = hotbarF.Slot3
local s4 = hotbarF.Slot4
local s5 = hotbarF.Slot5
local s6 = hotbarF.Slot6
local s7 = hotbarF.Slot7
local s8 = hotbarF.Slot8
local s9 = hotbarF.Slot9
local s10 = hotbarF.Slot10

local itemsSF = inventoryF.items
local closeB = inventoryF.Closebutton

local openB = gui.OpenButton

--Positions
local openP = UDim2.new(0.5,0,0.5,0)
local closeP = UDim2.new(0.5,0,1.5,0)


--Open/Close Function
local function openInventory()
	print(5)
	
	if inventoryF.Position ~= closeP then
		return
	end
	
	--Tweening
	local info = TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,false,0
	)
	local props = {
		Position = openP;
	}
	local tween = ts.Create(inventoryF,info,props)	
	
	inventoryF.Visible = true
	tween:Play()
	
end

local function closeInventory()
	print(4)
	
	if inventoryF.Position ~= openP then
		return
	end
end
--Tweening
local info = TweenInfo.new(
	1,
	Enum.EasingStyle.sine,
	Enum.EasingDirection.In,
	0,false,0
)
	local props = {
	Position = closeP;	
}
	local tween = ts:Create(inventoryF,info.props)

	tween:Play()
	tween.Completed:Wait()
	inventoryF.Visible = false

(end) <-- red line is here


print(0)
openB.MouseButton1Click:Connect(function()
	closeB.MouseButton1Click:Connect(closeInventory)
	print(1)
	if inventoryF.Position == openP then
		print(2)
		closeInventory
	elseif inventoryF.Position == closeP then
		print(3)
		openInventory()
	end
	
end)
closeB.MouseButton1Click:Connect(closeInventory)

here is the video and the part I am right now

3 Likes

It seems that there are some syntax errors in your code. Specifically, the closing parentheses for the closeInventory function and the tween variable declaration are misplaced.

can you revise the script to show where they are supposed to be placed

1 Like

This line might fix it:

local playerGui = player.PlayerGui

You’re overwriting the properties of the screengui, but the screengui isn’t affected, since Roblox is actually rendering the PlayerGui. Essentially, all screenguis are copied over to PlayerGui, and the non-functional ones are still in StarterGui. From playerGui you have to find the manual path to the inventory, and you can leave it be after the gui line
You’re welcome!

oye aye p.s i actually think i foundd another problem, the third line or player.CharacterAdded.Wait() is wrong, it’s supposed to be player.CharacterAdded:Wait()

also pls make slots a dictionary
i think closeB might have the path to the wrong thing unless the name is actually Closebutton not CloseButton since lua is case-sensitive

1 Like

Here:

-- Player Stuff
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded.Wait()

--Services
local ts = game:GetService("TweenService")
local debris = game:GetService("Debris")
--Gui
local gui = script.Parent
local hotbarF = gui.Hotbar; hotbarF.visible = true
local inventoryF = gui.inventory; inventoryF.visible = false

local s1 = hotbarF.Slot1
local s2 = hotbarF.Slot2
local s3 = hotbarF.Slot3
local s4 = hotbarF.Slot4
local s5 = hotbarF.Slot5
local s6 = hotbarF.Slot6
local s7 = hotbarF.Slot7
local s8 = hotbarF.Slot8
local s9 = hotbarF.Slot9
local s10 = hotbarF.Slot10

local itemsSF = inventoryF.items
local closeB = inventoryF.Closebutton

local openB = gui.OpenButton

--Positions
local openP = UDim2.new(0.5,0,0.5,0)
local closeP = UDim2.new(0.5,0,1.5,0)


--Open/Close Function
local function openInventory()
	print(5)

	if inventoryF.Position ~= closeP then
		return
	end

	--Tweening
	local info = TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,false,0
	)
	local props = {
		Position = openP;
	}
	local tween = ts.Create(inventoryF,info,props)	

	inventoryF.Visible = true
	tween:Play()

end

local function closeInventory()
	print(4)

	if inventoryF.Position ~= openP then
		return
	end
end


--Tweening
local info = TweenInfo.new(
	1,
	Enum.EasingStyle.sine,
	Enum.EasingDirection.In,
	0,false,0
)
local props = {
	Position = closeP;	
}
local tween = ts:Create(inventoryF,info.props)

tween:Play()
tween.Completed:Wait()
inventoryF.Visible = false

---(end) <-- red line is here  - You are end'ing nothing here. Remove it

	print(0)
openB.MouseButton1Click:Connect(function()
	closeB.MouseButton1Click:Connect(closeInventory)
	print(1)
	if inventoryF.Position == openP then
		print(2)
		closeInventory()  -- This line then errors as it is missing brackets
	elseif inventoryF.Position == closeP then
		print(3)
		openInventory()
	end

end)
closeB.MouseButton1Click:Connect(closeInventory)

2 Likes

Thanks ima try it out later and I will give u the green check mark if it works!

It removed all the syntax errors but it still doesnt work ;/

Btw here is the new updated script so far

-- Player Stuff
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

--Services
local ts = game:GetService("TweenService")
local debris = game:GetService("Debris")
--Gui
local playerGui = player.PlayerGui
local gui = script.Parent
local hotbarF = gui.Hotbar; hotbarF.visible = true
local inventoryF = gui.inventory; inventoryF.visible = false

local s1 = hotbarF.Slot1
local s2 = hotbarF.Slot2
local s3 = hotbarF.Slot3
local s4 = hotbarF.Slot4
local s5 = hotbarF.Slot5
local s6 = hotbarF.Slot6
local s7 = hotbarF.Slot7
local s8 = hotbarF.Slot8
local s9 = hotbarF.Slot9
local s10 = hotbarF.Slot10

local itemsSF = inventoryF.items
local closeB = inventoryF.Closebutton

local openB = gui.OpenButton

--Positions
local openP = UDim2.new(0.5,0,0.5,0)
local closeP = UDim2.new(0.5,0,1.5,0)


--Open/Close Function
local function openInventory()
	print(5)

	if inventoryF.Position ~= closeP then
		return
	end

	--Tweening
	local info = TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,false,0
	)
	local props = {
		Position = openP;
	}
	local tween = ts.Create(inventoryF,info,props)	

	inventoryF.Visible = true
	tween:Play()

end

local function closeInventory()
	print(4)

	if inventoryF.Position ~= openP then
		return
	end
end


--Tweening
local info = TweenInfo.new(
	1,
	Enum.EasingStyle.sine,
	Enum.EasingDirection.In,
	0,false,0
)
local props = {
	Position = closeP;	
}
local tween = ts:Create(inventoryF,info.props)

tween:Play()
tween.Completed:Wait()
inventoryF.Visible = false

---(end) <-- red line is here  - You are end'ing nothing here. Remove it

print(0)
openB.MouseButton1Click:Connect(function()
	closeB.MouseButton1Click:Connect(closeInventory)
	print(1)
	if inventoryF.Position == openP then
		print(2)
		closeInventory()  -- This line then errors as it is missing brackets
	elseif inventoryF.Position == closeB then
		print(3)
		openInventory()
	end

end)
closeB.MouseButton1Click:Connect(closeInventory)

1 Like

Can you tell me what errors you are getting if any? Also I can see that the script is based upon opening and closing an Inventory UI but what components of this aren’t working?

The ui doesnt open and close at all. When I click the open button nothing happens.

Could you try to debug by placing some print() functions around your code? Test your script and check the Output to see which part of the code prints and which doesn’t.

local hotbarF = gui.Hotbar; hotbarF.visible = true is the last line that it receives then the stack ends. Its pretty weird…

There was a couple of issues with a lack of capitalisation of key words, in particular “visible” versus “Visible”

Do you have the script Output window visible? This would have shown you a number of script errors and really helps to see what the errors are.

I have rewritten the open close functions and connects to simplify them:

--Positions
local openP = UDim2.new(0.5,0,0.5,0)
local closeP = UDim2.new(0.5,0,1.5,0)


--Open/Close Function
local function openInventory()
	print("OPEN Inventory")
	inventoryF.Visible = true
	inventoryF:TweenPosition(openP, "InOut", "Sine", 1)
end

local function closeInventory()
	print("CLOSE Inventory")
	inventoryF:TweenPosition(closeP, "InOut", "Sine", 1)
	task.wait(1)
	inventoryF.Visible = false
end


-- OPEN/CLOSE BUTTON
openB.Activated:Connect(function()
	if not inventoryF.Visible then  -- This is like a boolean check on the Visible property of the frame
		openInventory()
	else
		closeInventory()
	end
end)

-- INVENTORY CLOSE BUTTON
closeB.Activated:Connect(closeInventory)

I’ve used the .Activated event on the buttons as it handles both touch and mouse inputs.

ima try it rq. Thanks in advance.

Sorry it took me so long to respond I have been pretty busy lately. Can you add a dictionary. InventoryF CloseB OpenB are all unknown globals. I tried doing it myself but I could find how to define with local openb and closeb (plus the way I defined InventoryF is probably not the best :/) again sorry for the last response! All im asking is to revise the script so you can define listed above (and maybe even test it (if you have the time))

Hi. I just rewrote the script from the -- Positions comment downwards. The rest of the script above that should remain the same. I did make a quick recreation of your gui env. and it all works fine.

Ok Im going to try it probably on sunday (cuz I prob am gonna take a break from studio for a day.) Thanks for everything!

sry for bumping but seriously pls pls make slots a dictionary wahhhhh

ahhh. I will try but have been rlly busy lately. :P.