Files
Roblox-Elevator-Game/src/client/Player/CoreGuis.lua

97 lines
2.4 KiB
Lua

--!optimize 2
--!native
--!strict
type CustomCoreGuiEnums = {Enum.CoreGuiType}
type Impl_Constructor = {
On: (self: Impl_Constructor) -> (),
Off: (self: Impl_Constructor) -> (),
ForceOff: (self: Impl_Constructor) -> (),
ForceOn: (self: Impl_Constructor) -> (),
} & Impl_Static_Props
type Impl_Static_Props = {
AllowReset: boolean,
AllowEmotes: boolean,
AllowBackpack: boolean,
AllowPlayerList: boolean
}
local CoreGuis = {} :: Impl_Constructor
CoreGuis.AllowReset = false
CoreGuis.AllowEmotes = true
CoreGuis.AllowBackpack = false
CoreGuis.AllowPlayerList = false
local SG = game:GetService("StarterGui")
local Players = game:GetService("Players")
local function CustomCoreGuiEnums(): CustomCoreGuiEnums
local CoreElements = Enum.CoreGuiType:GetEnumItems()
table.remove(CoreElements, table.find(CoreElements, Enum.CoreGuiType.All))
if CoreGuis.AllowBackpack then
table.remove(CoreElements, table.find(CoreElements, Enum.CoreGuiType.Backpack))
end
if CoreGuis.AllowEmotes then
table.remove(CoreElements, table.find(CoreElements, Enum.CoreGuiType.EmotesMenu))
end
if CoreGuis.AllowPlayerList then
table.remove(CoreElements, table.find(CoreElements, Enum.CoreGuiType.PlayerList))
end
return CoreElements
end
local function ResetEnabled(enabled: boolean)
--Roblox actually doesn't register this fast enough so we gotta resort to cringe tactics
repeat
local PossibleMemoryLeak = pcall(SG.SetCore, SG, "ResetButtonCallback", enabled)
task.wait()
until PossibleMemoryLeak
end
function CoreGuis:On()
local Elements = CustomCoreGuiEnums()
for i = 1, #Elements do
SG:SetCoreGuiEnabled(Elements[i], true)
end
ResetEnabled(CoreGuis.AllowReset)
end
function CoreGuis:Off()
if #Players:GetPlayers()>1 then
--Enable multiplayer features
self:On()
local PlayerAdded
PlayerAdded = Players.PlayerAdded:Connect(function(_)
if #Players:GetPlayers()>1 then
self:On()
--We dont need to listen for players anymore
PlayerAdded:Disconnect()
end
end)
else
local Elements = CustomCoreGuiEnums()
for i = 1, #Elements do
SG:SetCoreGuiEnabled(Elements[i], false)
end
end
ResetEnabled(CoreGuis.AllowReset)
end
function CoreGuis:ForceOff()
SG:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
ResetEnabled(false)
end
function CoreGuis:ForceOn()
SG:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
ResetEnabled(true)
end
return CoreGuis