[✅SOLVED] - How to make a Module Script that close other frames?

Hello Everyone!

I would like to know how to make a Module Script that close the opened frame and open the frame chosen.

How do I want?
Local Script

ModuleScript.OpenUi(frame)

Module Script :

local CurrentlyOpenedUi = nil

function module.OpenUi(frame)
frame.Visible = true
CurrentlyUiOpened.Visible = false

CurrentlyOpenedUi = frame

end

This is how I want but the CurrentlyOpenedUi doesn’t close. Please Help!!

2 Likes

You need to make sure you are doing a check and make sure that CurrentlyUiOpened isn’t nil. From what I see, the first time its ran: CurrentlyUiOpened is nil and doing nil.Visible = false will throw an error.

2 Likes

Thank You, I will test the code and see if it works!

This is the Updated Script.

Thank You to @Map1eMoose for helping me!

local module = {}

local CurrentlyOpenedUi = nil

function module.OpenUi(frame)

	if CurrentlyOpenedUi ~= nil then
		if CurrentlyOpenedUi == frame then
			frame.Visible = false
			CurrentlyOpenedUi = nil
			return
		else
			CurrentlyOpenedUi.Visible = false
		end
	else
	end

	if frame.Visible == false then
		frame.Visible = true
	else
		frame.Visible = false
	end

	CurrentlyOpenedUi = frame
end

return module

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.