Advertisement
Inqxii

Untitled

Mar 25th, 2023
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.50 KB | None | 0 0
  1. local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
  2. local lPlr = game:GetService("Players").LocalPlayer
  3. local library = require(script.Parent.Parent:WaitForChild("Modules").library)
  4. local ts = game:GetService("TweenService")
  5. local playerGui = library.playerGui
  6. local icon = library.loading.icon
  7. local loading = playerGui:WaitForChild("LoadingV2")
  8. loading.Enabled = true
  9.  
  10. local cameraController
  11. local uiController
  12. local islandService
  13. local characterConnection
  14.  
  15. local assets = {game.Workspace:GetDescendants(); game.ReplicatedStorage:GetDescendants(); game:GetService("Players").LocalPlayer.PlayerScripts:GetDescendants(); game:GetService("Players").LocalPlayer.PlayerGui:GetDescendants();}
  16.  
  17. local loadController = Knit.CreateController { Name = "LoadController"}
  18. local count = 0
  19. local total = 0
  20. local finishedLoading = false
  21. local playClicked = false
  22. local click
  23. local hoverEnter
  24. local hoverLeave
  25.  
  26. -- Colors for loading icon gradient
  27. local c1 = Color3.fromRGB(186, 67, 255)
  28. local c2 = Color3.fromRGB(156, 106, 255)
  29. local c3 = Color3.new(0, 0, 0)
  30.  
  31.  
  32. local iconTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  33. local iconRotationInfo = TweenInfo.new(1.25, Enum.EasingStyle.Back, Enum.EasingDirection.In)
  34. local iconRotationTween = ts:Create(icon, iconRotationInfo, {Rotation = 360})
  35. local totalCount = 0
  36. for i, v in pairs(assets) do
  37.     totalCount = #v + totalCount
  38. end
  39. total = totalCount
  40.  
  41. -- Updates the roblox icon's gradient after every rotation to show the loading progress
  42. function loadController:tweenIconGradient(loaded)
  43.     -- local newSequence
  44.     -- print(loaded)
  45.     ts:Create(icon.UIGradient, iconTweenInfo, {Offset = Vector2.new(0, -1 + loaded)}):Play()
  46.     -- icon.UIGradient.Color = newSequence
  47. end
  48.  
  49.  
  50.  
  51. function loadController:Play()
  52.    
  53. end
  54.  
  55.  
  56. function loadController:finishLoading()
  57.     print("Finished loading game")
  58.     lPlr.Character:FindFirstChild("Torso").Anchored = true
  59.     local island
  60.     islandService:getIsland():andThen(function(islandReturned)
  61.         island = islandReturned
  62.     end)
  63.     local transparencyInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
  64.     local transparencyInfo2 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
  65.     game:GetService("SoundService"):FindFirstChild("IntroWave"):Play()
  66.     ts:Create(icon, transparencyInfo, {ImageTransparency = 1}):Play()
  67.     task.wait(1)
  68.     icon.Visible = false
  69.     ts:Create(loading.LoadingScreen:FindFirstChild("Logo"), transparencyInfo2, {ImageTransparency = 0}):Play()
  70.     ts:Create(loading.LoadingScreen:FindFirstChild("LogoText"), transparencyInfo2, {TextTransparency = 0}):Play()
  71.     task.wait(2)
  72.  
  73.     ts:Create(loading.LoadingScreen:FindFirstChild("Logo"), transparencyInfo2, {ImageTransparency = 1}):Play()
  74.     ts:Create(loading.LoadingScreen:FindFirstChild("LogoText"), transparencyInfo2, {TextTransparency = 1}):Play()
  75.     ts:Create(loading.LoadingScreen, transparencyInfo2, {BackgroundTransparency = 1}):Play()
  76.     cameraController:rotateAroundPart(island.Island:FindFirstChild("Island").Spawn.Spawn, 150, 45)
  77.     task.wait(2)
  78.     loading.LoadingScreen:FindFirstChild("Logo").Visible = false
  79.     loading.LoadingScreen:FindFirstChild("LogoText").Visible = false
  80.     loading.LoadingScreen:FindFirstChild("Play").Visible = true
  81.  
  82.     local hoverInfo = {
  83.         direction = Enum.EasingDirection.Out,
  84.         style = Enum.EasingStyle.Quad,
  85.         tweenTime = 0.13
  86.     }
  87.     local clickInfo = {
  88.         direction = Enum.EasingDirection.In,
  89.         style = Enum.EasingStyle.Back,
  90.         tweenTime = 0.15
  91.     }
  92.     uiController:newButton(true, true, loading.LoadingScreen:FindFirstChild("Play"), hoverInfo, clickInfo, "Play")
  93.     hoverEnter = loading.LoadingScreen:FindFirstChild("Play").MouseEnter:Connect(function()
  94.         loading.LoadingScreen.Play.Icon.ImageColor3 = Color3.fromRGB(200, 200, 200)
  95.     end)
  96.     hoverEnter = loading.LoadingScreen:FindFirstChild("Play").MouseLeave:Connect(function()
  97.         loading.LoadingScreen.Play.Icon.ImageColor3 = Color3.new(1, 1, 1)
  98.     end)
  99.     click = loading.LoadingScreen:FindFirstChild("Play").MouseButton1Click:Connect(function()
  100.         playClicked = true
  101.         task.wait(0.23)
  102.         loading.LoadingScreen:FindFirstChild("Play").Visible = false
  103.         coroutine.wrap(function()
  104.             cameraController:tweenToCFrame(lPlr.Character.Head.CFrame, Enum.EasingStyle.Back, Enum.EasingDirection.In, 0.9)
  105.         end)()
  106.         lPlr.Character:FindFirstChild("Torso").Anchored = false
  107.         library.main.Enabled = true
  108.         click:Disconnect()
  109.     end)
  110.  
  111.  
  112. end
  113.  
  114.  
  115. function loadController:initLoading()
  116.     lPlr.Character:FindFirstChild("Torso").Anchored = true
  117.     coroutine.wrap(function()
  118.         while true do
  119.             iconRotationTween:Play()
  120.             task.wait(1.3)
  121.             icon.Rotation = 0
  122.             loadController:tweenIconGradient(count/total)
  123.             if finishedLoading == true then break end
  124.         end
  125.     end)()
  126.     coroutine.wrap(function()
  127.         while true do
  128.             if finishedLoading == true then break end
  129.             local newCircle = Instance.new("Frame")
  130.             local randomSize = math.random(3, 7)/100
  131.             newCircle.Size = UDim2.new(randomSize, 0, randomSize, 0)
  132.             newCircle.Visible = true
  133.             newCircle.ZIndex = 1
  134.             newCircle.BackgroundTransparency = 0.9
  135.             local newAR = Instance.new("UIAspectRatioConstraint")
  136.             newAR.AspectRatio = 1
  137.             newAR.DominantAxis = Enum.DominantAxis.Width
  138.             newAR.AspectType = Enum.AspectType.FitWithinMaxSize
  139.             newAR.Parent = newCircle
  140.             local randomColor = math.random(1, 8)/10
  141.             local randomEndPosX = math.random(0, 40)/100
  142.             local randomEndPosY = math.random(20, 80)/100
  143.             local randomSide = math.random(1, 2)
  144.             if randomSide == 2 then
  145.                 randomEndPosX = 1 - randomEndPosX
  146.             end
  147.             local endUDim2 = UDim2.new(randomEndPosX, 0, randomEndPosY, 0)
  148.             if randomSide == 1 then
  149.                 newCircle.Position = UDim2.new(0, 0, 1, 0)
  150.             else
  151.                 newCircle.Position = UDim2.new(1, 0, 1, 0)
  152.             end
  153.             local corner = Instance.new("UICorner")
  154.             corner.Parent = newCircle
  155.             corner.CornerRadius = UDim.new(1, 0)
  156.             newCircle.BackgroundColor3 = Color3.new(randomColor, randomColor, randomColor)
  157.             newCircle.Parent = library.loading.screen.LoadingScreen
  158.             newCircle:TweenPosition(endUDim2, Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 3)
  159.             coroutine.wrap(function()
  160.                 task.wait(3)
  161.                 newCircle:Destroy()
  162.             end)()
  163.             task.wait(0.15)
  164.         end
  165.     end)()
  166.     for _, s in pairs(assets) do
  167.         for n, a in pairs(s) do
  168.             game.ContentProvider:PreloadAsync({a})
  169.             count = count + 1
  170.             -- print(count.."/"..totalCount)
  171.         end
  172.     end
  173.     finishedLoading = true
  174.     return "Loaded"
  175. end
  176.  
  177.  
  178. function loadController:init()
  179. end
  180.  
  181.  
  182. function loadController:KnitStart()
  183.     cameraController = Knit.GetController("CameraController")
  184.     uiController = Knit.GetController("UIController")
  185.     islandService = Knit.GetService("IslandService")
  186.     local timeCalled = tick()
  187.  
  188.     icon:WaitForChild("UIGradient").Color = ColorSequence.new{
  189.         ColorSequenceKeypoint.new(0, c1),
  190.         ColorSequenceKeypoint.new(0.999, c2),
  191.         ColorSequenceKeypoint.new(1, c3)
  192.     }
  193.     icon.UIGradient.Offset = Vector2.new(0,-1)
  194.     characterConnection = lPlr.CharacterAdded:Connect(function(char)
  195.         if playClicked == false then
  196.             char:FindFirstChild("Torso").Anchored = true
  197.         else
  198.             characterConnection:Disconnect()
  199.         end
  200.     end)
  201.     loadController:initLoading()
  202.     loadController:finishLoading()
  203.     local timeFinished = tick()
  204.     local totalCounted = timeFinished - timeCalled
  205.     print("loadController initialized: took "..totalCounted.." seconds")
  206. end
  207.  
  208. function loadController:KnitInit()
  209.     loading.Enabled = true
  210.     game.ContentProvider:PreloadAsync({icon})
  211.     game.ContentProvider:PreloadAsync({library.loading.screen:WaitForChild("LoadingScreen")})
  212. end
  213.  
  214. return loadController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement