Advertisement
HowToRoblox

MainMenuHandler

Oct 4th, 2020 (edited)
15,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.12 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2.  
  3. local char = plr.Character or plr.CharacterAdded:Wait()
  4. char:WaitForChild("HumanoidRootPart").Anchored = true
  5.  
  6.  
  7. local mouse = plr:GetMouse()
  8.  
  9.  
  10. local camera = workspace.CurrentCamera
  11.  
  12. camera.CameraType = Enum.CameraType.Scriptable
  13. camera.CFrame = workspace.MenuComponents.CameraStartPosition.CFrame
  14.  
  15.  
  16. local tweenService = game:GetService("TweenService")
  17.  
  18.  
  19. local mainMenuGui = script.Parent
  20.  
  21.  
  22. local mainMenuBG = mainMenuGui:WaitForChild("MainMenuBackground")
  23.  
  24. local playBtn = mainMenuBG:WaitForChild("PlayButton")
  25. local creditsBtn = mainMenuBG:WaitForChild("CreditsButton")
  26.  
  27. local creditsBG = mainMenuBG:WaitForChild("CreditsBackground")
  28.  
  29.  
  30. local loadingScreenBG = mainMenuGui:WaitForChild("LoadingScreenBackground")
  31.  
  32. local logo = loadingScreenBG:WaitForChild("Logo")
  33.  
  34. local loadingBarBG = loadingScreenBG:WaitForChild("LoadingBarBG")
  35. local clippingFrame = loadingBarBG:WaitForChild("ClippingFrame")
  36. local loadingBar = clippingFrame:WaitForChild("LoadingBar")
  37.  
  38.  
  39. clippingFrame.Size = UDim2.new(0, 0, 1, 0)
  40.  
  41. clippingFrame:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 5)
  42.  
  43.  
  44. clippingFrame:GetPropertyChangedSignal("Size"):Connect(function()  
  45.    
  46.     loadingBar.Size = UDim2.new(1/clippingFrame.Size.X.Scale, 0, 1, 0)
  47. end)
  48.  
  49.  
  50. repeat wait() until clippingFrame.Size == UDim2.new(1, 0, 1, 0)
  51.  
  52.  
  53. local loadingScreenFade = tweenService:Create(loadingScreenBG, TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})
  54. loadingScreenFade:Play()
  55.  
  56. logo:TweenPosition(UDim2.new(0.5, 0, -0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2)
  57. loadingBarBG:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2)
  58.  
  59.  
  60.  
  61. local originalCFrame = camera.CFrame
  62. local scaleFactor = 1000
  63.  
  64.  
  65. game:GetService("RunService").RenderStepped:Connect(function()
  66.    
  67.    
  68.     local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
  69.    
  70.     local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0)
  71.    
  72.    
  73.     camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre)
  74. end)
  75.  
  76.  
  77. local playButtonClicked = false
  78.  
  79. playBtn.MouseButton1Click:Connect(function()
  80.    
  81.     if playButtonClicked then return end
  82.     playButtonClicked = true
  83.    
  84.    
  85.     creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
  86.    
  87.     mainMenuBG:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true)
  88.    
  89.    
  90.     wait(3)
  91.    
  92.    
  93.     char.HumanoidRootPart.Anchored = false
  94.     char.HumanoidRootPart.CFrame = workspace.MenuComponents.SpawnPart.CFrame
  95.    
  96.     camera.CameraType = Enum.CameraType.Custom
  97.    
  98.     mainMenuGui:Destroy()
  99. end)
  100.  
  101.  
  102. local creditsOpen = false
  103.  
  104. creditsBtn.MouseButton1Click:Connect(function()
  105.    
  106.    
  107.     if playButtonClicked then return end
  108.    
  109.    
  110.     if creditsOpen then
  111.         creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
  112.        
  113.     else
  114.         creditsBG:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
  115.     end
  116.    
  117.     creditsOpen = not creditsOpen
  118. end)
  119.  
  120.  
  121. local function hoverOnButton(btn)
  122.    
  123.     if playButtonClicked then return end
  124.    
  125.     local colourDarken = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(221, 221, 221)})
  126.     colourDarken:Play()
  127. end
  128.  
  129. local function hoverOffButton(btn)
  130.    
  131.     if playButtonClicked then return end
  132.    
  133.     local colourNormal = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(255, 255, 255)})
  134.     colourNormal:Play()
  135. end
  136.  
  137.  
  138. playBtn.MouseEnter:Connect(function()
  139.    
  140.     hoverOnButton(playBtn)
  141. end)
  142. creditsBtn.MouseEnter:Connect(function()
  143.    
  144.     hoverOnButton(creditsBtn)
  145. end)
  146.  
  147. playBtn.MouseLeave:Connect(function()
  148.    
  149.     hoverOffButton(playBtn)
  150. end)
  151. creditsBtn.MouseLeave:Connect(function()
  152.    
  153.     hoverOffButton(creditsBtn)
  154. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement