Guest User

Main Menu Script

a guest
Jul 19th, 2024
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.29 KB | Source Code | 0 0
  1.  -- !strict
  2. local blur = game.Lighting.Blur
  3. local settingsFrame = script.Parent.Settings
  4. local mainFrame = script.Parent.Frame
  5. local LoadingScreen = script.Parent.Loading
  6. local ContentProvider = game:GetService("ContentProvider")
  7.  
  8. mainFrame.Visible = true
  9.  
  10. local ReplicatedFirst = game:GetService("ReplicatedFirst")
  11. local PlayButton = LoadingScreen:WaitForChild("PlayButton")
  12. --ReplicatedFirst:RemoveDefaultLoadingScreen()
  13.  
  14. -- Controller Support
  15. local UserInputService = game:GetService("UserInputService")
  16. local ContextActionService = game:GetService("ContextActionService")
  17.  
  18. -- Controller UI
  19. local ControllerSettingsUI = script.Parent.ControllerSupport.UI.ControllerSettings
  20. local GamePadSettingsUI = script.Parent.ControllerSupport.UI.GamePadSettings
  21. local ButtonGradient = Instance.new("UIGradient")
  22. ButtonGradient.Parent = nil
  23. ButtonGradient.Enabled = true
  24. ButtonGradient.Rotation = 90
  25.  
  26. local keypoint1 = ColorSequenceKeypoint.new(0, Color3.fromRGB(150, 150, 150))
  27. local keypoint2 = ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 255, 255))
  28.  
  29. ButtonGradient.Color = ColorSequence.new(keypoint1, keypoint2)
  30.  
  31.  
  32.  
  33. local tweenservice = game.TweenService
  34. local TInfoParams = TweenInfo.new(0.3,
  35.     Enum.EasingStyle.Sine,
  36.     Enum.EasingDirection.InOut
  37. )
  38.  
  39. blur.Enabled = true
  40.  
  41. local Player = game.Players.LocalPlayer
  42. local Character = Player.Character or Player.CharacterAdded:Wait()
  43. local Camera = workspace.CurrentCamera
  44.  
  45. -- LoadingScreen.Visible = true
  46.  
  47. repeat wait()
  48.     Camera.CameraType = Enum.CameraType.Scriptable
  49. until Camera.CameraType == Enum.CameraType.Scriptable
  50. Camera.CFrame = workspace.CameraPart.CFrame
  51.  
  52. local function PlayGame()
  53.     task.wait(0.1)
  54.     script.Parent.Frame.Visible = false
  55.     tweenservice:Create(blur, TInfoParams, {Size = 0}):Play()
  56.     Camera.CameraType = Enum.CameraType.Custom
  57. end
  58.  
  59. local function OpenSettings()
  60.     settingsFrame.Rotation = 90 -- just to set up the visuals
  61.     settingsFrame.Size = UDim2.new(0, 0, 0, 0)
  62.     wait(0.1)
  63.     game.ReplicatedStorage.Sounds.FrameOpen:Play()
  64.     settingsFrame.Visible = true
  65.     tweenservice:Create(settingsFrame, TInfoParams, {Rotation = -5}):Play()
  66.     tweenservice:Create(settingsFrame, TInfoParams, {Size = UDim2.new(0.31, 0, 0.409, 0)}):Play()
  67. end
  68.  
  69. local function ExitSettings()
  70.     tweenservice:Create(settingsFrame, TInfoParams, {Rotation = 90}):Play()
  71.     tweenservice:Create(settingsFrame, TInfoParams, {Size = UDim2.new(0, 0, 0, 0)}):Play()
  72.     wait(0.32)
  73.     settingsFrame.Visible = false
  74. end
  75.  
  76. mainFrame.PlayButton.MouseButton1Down:Connect(function()
  77.     PlayGame()
  78. end)
  79.  
  80. mainFrame.Settings.MouseButton1Down:Connect(function()
  81.     OpenSettings()
  82. end)
  83.  
  84. settingsFrame.Exit.MouseButton1Down:Connect(function()
  85.     ExitSettings()
  86. end)
  87.  
  88. -- Controller Support
  89.  
  90. local DEADZONE: number = 0.1 -- 0-1
  91.  
  92. -- Everything Within one Function.
  93.  
  94. GamePadSettingsUI.Visible = false
  95. ControllerSettingsUI.Position = UDim2.new(1.5, 0, 0.502, 0)
  96.  
  97. local function OpenGamePadSettingsUI()
  98.     tweenservice:Create(GamePadSettingsUI, TInfoParams, {Position = UDim2.new(0.5, 0, 0.499, 0)}):Play()
  99.     GamePadSettingsUI.Visible = true
  100. end
  101.  
  102. local function CloseGamePadSettingsUI()
  103.     tweenservice:Create(GamePadSettingsUI, TInfoParams, {Position = UDim2.new(0.5, 0, 0, 0)}):Play()
  104.     GamePadSettingsUI.Visible = false
  105. end
  106.  
  107. UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
  108.     if gameProcessedEvent then
  109.  
  110.     end
  111.     if GamePadSettingsUI.Visible == true then
  112.         if input.KeyCode == Enum.KeyCode.ButtonR2 then
  113.             tweenservice:Create(GamePadSettingsUI, TInfoParams, {Position = UDim2.new(0.5, 0, 0, 0)}):Play()
  114.             GamePadSettingsUI.Visible = false
  115.             script.Beep:Play()
  116.         end
  117.     end
  118.    
  119. end)
  120.  
  121.  
  122. UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
  123.     if gameProcessedEvent then
  124.        
  125.     end
  126.    
  127.     if input.KeyCode == Enum.KeyCode.Thumbstick1 and input.Position.Magnitude > DEADZONE then
  128.         print(input.Position.X, input.Position.Y)
  129.         if input.Position.X > 0 then
  130.             print("Right GamePad")
  131.             OpenGamePadSettingsUI()
  132.             script.Beep:Play()
  133.         elseif input.Position.X < 0 then
  134.             print("Left GamePad")
  135.             PlayGame()
  136.             script.Beep:Play()
  137.         end
  138.     end
  139. end)
  140.  
  141. UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
  142.     if gameProcessedEvent then
  143.        
  144.     end
  145.    
  146.     if input.KeyCode == Enum.KeyCode.ButtonL1 and GamePadSettingsUI.Visible == true then
  147.         CloseGamePadSettingsUI()
  148.         script.Beep:Play()
  149.     end
  150.  
  151. end)
  152.  
  153. UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
  154.     if gameProcessedEvent then
  155.        
  156.     end
  157.     if input.KeyCode == Enum.KeyCode.ButtonA and GamePadSettingsUI.Controller.Selected then
  158.         print("Selected")
  159.         ButtonGradient.Parent = GamePadSettingsUI.Controller
  160.         tweenservice:Create(ControllerSettingsUI, TInfoParams, {Position = UDim2.new(0.498, 0, 0.502, 0)}):Play()
  161.         script.Beep:Play()
  162.     end
  163.        
  164. end)
  165.  
  166. ControllerSettingsUI.SelectionLost:Connect(function()
  167.     print("Selection lost")
  168.     ButtonGradient.Parent = nil
  169.     tweenservice:Create(ControllerSettingsUI, TInfoParams, {Position = UDim2.new(1.5, 0, 0.502, 0)}):Play()
  170.     script.Beep:Play()
  171. end)
  172.  
  173. -- Detect if Keyboard is Enabled
  174. if UserInputService.KeyboardEnabled then
  175.     local icons = script.Parent.Icons:GetDescendants()
  176.     for _, icon in pairs(icons) do
  177.         if icon:IsA("ImageButton") then
  178.             icon.Visible = false
  179.         end
  180.     end
  181. end
  182.  
  183. if UserInputService.GamepadEnabled then
  184.     local icons = script.Parent.Icons:GetDescendants()
  185.     for _, icon in pairs(icons) do
  186.         if icon:IsA("ImageButton") then
  187.             icon.Visible = true
  188.         end
  189.     end
  190. end
  191.  
  192. local UserInputService = game:GetService("UserInputService")
  193.  
  194. local function getActiveGamepad()
  195.     local activeGamepad = nil
  196.  
  197.     local connectedGamepads = UserInputService:GetConnectedGamepads()
  198.  
  199.     if #connectedGamepads > 0 then
  200.         for _, gamepad in connectedGamepads do
  201.             if activeGamepad == nil or gamepad.Value < activeGamepad.Value then
  202.                 activeGamepad = gamepad
  203.             end
  204.         end
  205.     end
  206.  
  207.     if activeGamepad == nil then  -- Nothing is connected; set up for "Gamepad1"
  208.         activeGamepad = Enum.UserInputType.Gamepad1
  209.         local icons = script.Parent.ControllerSupport.Icons:GetDescendants()
  210.         for _, icon in pairs(icons) do
  211.             if icon:IsA("ImageButton") then
  212.                 icon.Visible = false
  213.             end
  214.         end
  215.     end
  216.  
  217.     return activeGamepad
  218. end
  219.  
  220. if UserInputService.GamepadEnabled then
  221.     local activeGamepad = getActiveGamepad()
  222.     print(activeGamepad)
  223. end
  224.  
  225. local GamePadActive = getActiveGamepad()
  226.  
  227. if GamePadActive == false then
  228.     print("No Gamepad Detected")
  229.     -- Repeat Line 118
  230.     local icons = script.Parent.ControllerSupport.Icons:GetDescendants()
  231.     for _, icon in pairs(icons) do
  232.         if icon:IsA("ImageButton") then
  233.             icon.Visible = false
  234.         end
  235.     end
  236. end
  237.  
  238.  
  239. UserInputService.GamepadConnected:Connect(function(gamepad)
  240.     print("User has connected controller: " .. tostring(gamepad))
  241.     local icons = script.Parent.ControllerSupport.Icons:GetDescendants()
  242.     for _, icon in pairs(icons) do
  243.         if icon:IsA("ImageButton") then
  244.             icon.Visible = true
  245.         end
  246.     end
  247. end)
  248.  
  249. UserInputService.GamepadDisconnected:Connect(function(gamepad)
  250.     print("User has disconnected controller: " .. tostring(gamepad))
  251.     local icons = script.Parent.ControllerSupport.Icons:GetDescendants()
  252.     for _, icon in pairs(icons) do
  253.         if icon:IsA("ImageButton") then
  254.             icon.Visible = false
  255.         end
  256.     end
  257. end)
  258.  
Advertisement
Add Comment
Please, Sign In to add comment