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.
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