
-- Creates all neccessary scripts for the gui on initial load, everything except build tools
-- Created by Ben T. 10/29/10
-- Please note that these are loaded in a specific order to diminish errors/perceived load time by user
local scriptContext = game:GetService("ScriptContext")

-- library registration
scriptContext:AddStarterScript(60595695)

local function waitForChild(instance, name)
	while not instance:FindFirstChild(name) do
		instance.ChildAdded:wait()
	end
end
local function waitForProperty(instance, property)
	while not instance[property] do
		instance.Changed:wait()
	end
end

-- Responsible for tracking logging items
local scriptContext = game:GetService("ScriptContext")
scriptContext:AddCoreScript(59002209, scriptContext, "Sections")

waitForChild(game:GetService("CoreGui"),"RobloxGui")
local screenGui = game:GetService("CoreGui"):FindFirstChild("RobloxGui")

-- SettingsScript 
scriptContext:AddCoreScript(46295863,screenGui,"SettingsScript")

-- MainBotChatScript
scriptContext:AddCoreScript(39250920,screenGui,"MainBotChatScript")

scriptContext:AddCoreScript(70412866,screenGui,"ChatScript")

-- Purchase Prompt Script
scriptContext:AddCoreScript(70413270, screenGui, "CoreScripts/PurchasePromptScript")

-- Dev Console
scriptContext:AddCoreScript(70424641, screenGui, "CoreScripts/DeveloperConsole")


if game.CoreGui.Version >= 2 then
	-- New Player List
	scriptContext:AddCoreScript(48488235,screenGui,"PlayerListScript")
	-- Popup Script
	scriptContext:AddCoreScript(48488451,screenGui,"PopupScript")
	-- Friend Notification Script (probably can use this script to expand out to other notifications)
	scriptContext:AddCoreScript(48488398,screenGui,"NotificationScript")
end

--if game.CoreGui.Version >= 3 then	
	-- Backpack Builder
	scriptContext:AddCoreScript(53878047,screenGui,"CoreScripts/BackpackScripts/BackpackBuilder")
	waitForChild(screenGui,"CurrentLoadout")
	waitForChild(screenGui.CurrentLoadout,"TempSlot")
	waitForChild(screenGui.CurrentLoadout.TempSlot,"SlotNumber")

	scriptContext:AddCoreScript(70397612,Backpack,"CoreScripts/BackpackScripts/BackpackManager")
	-- Backpack Script
	scriptContext:AddCoreScript(53878057,screenGui.CurrentLoadout,"CoreScripts/BackpackScripts/LoadoutScript")
--end

local IsPersonalServer = not not game.Workspace:FindFirstChild("PSVariable")
if IsPersonalServer then	
	game:GetService("ScriptContext"):AddCoreScript(70397613,game.Players.LocalPlayer,"BuildToolManager")
end
game.Workspace.ChildAdded:connect(function(nchild)
	if nchild.Name=='PSVariable' and nchild:IsA('BoolValue') then
		IsPersonalServer = true		
		game:GetService("ScriptContext"):AddCoreScript(70397613,game.Players.LocalPlayer,"BuildToolManager")
	end
end)

if Game:GetService("UserInputService").TouchEnabled then
	scriptContext:AddCoreScript(70423403, screenGui, "CoreScripts/TouchControls")
end