Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
- local lPlr = game:GetService("Players").LocalPlayer
- local library = require(script.Parent.Parent:WaitForChild("Modules").library)
- local ts = game:GetService("TweenService")
- local playerGui = library.playerGui
- local icon = library.loading.icon
- local loading = playerGui:WaitForChild("LoadingV2")
- loading.Enabled = true
- local cameraController
- local uiController
- local islandService
- local characterConnection
- local assets = {game.Workspace:GetDescendants(); game.ReplicatedStorage:GetDescendants(); game:GetService("Players").LocalPlayer.PlayerScripts:GetDescendants(); game:GetService("Players").LocalPlayer.PlayerGui:GetDescendants();}
- local loadController = Knit.CreateController { Name = "LoadController"}
- local count = 0
- local total = 0
- local finishedLoading = false
- local playClicked = false
- local click
- local hoverEnter
- local hoverLeave
- -- Colors for loading icon gradient
- local c1 = Color3.fromRGB(186, 67, 255)
- local c2 = Color3.fromRGB(156, 106, 255)
- local c3 = Color3.new(0, 0, 0)
- local iconTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
- local iconRotationInfo = TweenInfo.new(1.25, Enum.EasingStyle.Back, Enum.EasingDirection.In)
- local iconRotationTween = ts:Create(icon, iconRotationInfo, {Rotation = 360})
- local totalCount = 0
- for i, v in pairs(assets) do
- totalCount = #v + totalCount
- end
- total = totalCount
- -- Updates the roblox icon's gradient after every rotation to show the loading progress
- function loadController:tweenIconGradient(loaded)
- -- local newSequence
- -- print(loaded)
- ts:Create(icon.UIGradient, iconTweenInfo, {Offset = Vector2.new(0, -1 + loaded)}):Play()
- -- icon.UIGradient.Color = newSequence
- end
- function loadController:Play()
- end
- function loadController:finishLoading()
- print("Finished loading game")
- lPlr.Character:FindFirstChild("Torso").Anchored = true
- local island
- islandService:getIsland():andThen(function(islandReturned)
- island = islandReturned
- end)
- local transparencyInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
- local transparencyInfo2 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
- game:GetService("SoundService"):FindFirstChild("IntroWave"):Play()
- ts:Create(icon, transparencyInfo, {ImageTransparency = 1}):Play()
- task.wait(1)
- icon.Visible = false
- ts:Create(loading.LoadingScreen:FindFirstChild("Logo"), transparencyInfo2, {ImageTransparency = 0}):Play()
- ts:Create(loading.LoadingScreen:FindFirstChild("LogoText"), transparencyInfo2, {TextTransparency = 0}):Play()
- task.wait(2)
- ts:Create(loading.LoadingScreen:FindFirstChild("Logo"), transparencyInfo2, {ImageTransparency = 1}):Play()
- ts:Create(loading.LoadingScreen:FindFirstChild("LogoText"), transparencyInfo2, {TextTransparency = 1}):Play()
- ts:Create(loading.LoadingScreen, transparencyInfo2, {BackgroundTransparency = 1}):Play()
- cameraController:rotateAroundPart(island.Island:FindFirstChild("Island").Spawn.Spawn, 150, 45)
- task.wait(2)
- loading.LoadingScreen:FindFirstChild("Logo").Visible = false
- loading.LoadingScreen:FindFirstChild("LogoText").Visible = false
- loading.LoadingScreen:FindFirstChild("Play").Visible = true
- local hoverInfo = {
- direction = Enum.EasingDirection.Out,
- style = Enum.EasingStyle.Quad,
- tweenTime = 0.13
- }
- local clickInfo = {
- direction = Enum.EasingDirection.In,
- style = Enum.EasingStyle.Back,
- tweenTime = 0.15
- }
- uiController:newButton(true, true, loading.LoadingScreen:FindFirstChild("Play"), hoverInfo, clickInfo, "Play")
- hoverEnter = loading.LoadingScreen:FindFirstChild("Play").MouseEnter:Connect(function()
- loading.LoadingScreen.Play.Icon.ImageColor3 = Color3.fromRGB(200, 200, 200)
- end)
- hoverEnter = loading.LoadingScreen:FindFirstChild("Play").MouseLeave:Connect(function()
- loading.LoadingScreen.Play.Icon.ImageColor3 = Color3.new(1, 1, 1)
- end)
- click = loading.LoadingScreen:FindFirstChild("Play").MouseButton1Click:Connect(function()
- playClicked = true
- task.wait(0.23)
- loading.LoadingScreen:FindFirstChild("Play").Visible = false
- coroutine.wrap(function()
- cameraController:tweenToCFrame(lPlr.Character.Head.CFrame, Enum.EasingStyle.Back, Enum.EasingDirection.In, 0.9)
- end)()
- lPlr.Character:FindFirstChild("Torso").Anchored = false
- library.main.Enabled = true
- click:Disconnect()
- end)
- end
- function loadController:initLoading()
- lPlr.Character:FindFirstChild("Torso").Anchored = true
- coroutine.wrap(function()
- while true do
- iconRotationTween:Play()
- task.wait(1.3)
- icon.Rotation = 0
- loadController:tweenIconGradient(count/total)
- if finishedLoading == true then break end
- end
- end)()
- coroutine.wrap(function()
- while true do
- if finishedLoading == true then break end
- local newCircle = Instance.new("Frame")
- local randomSize = math.random(3, 7)/100
- newCircle.Size = UDim2.new(randomSize, 0, randomSize, 0)
- newCircle.Visible = true
- newCircle.ZIndex = 1
- newCircle.BackgroundTransparency = 0.9
- local newAR = Instance.new("UIAspectRatioConstraint")
- newAR.AspectRatio = 1
- newAR.DominantAxis = Enum.DominantAxis.Width
- newAR.AspectType = Enum.AspectType.FitWithinMaxSize
- newAR.Parent = newCircle
- local randomColor = math.random(1, 8)/10
- local randomEndPosX = math.random(0, 40)/100
- local randomEndPosY = math.random(20, 80)/100
- local randomSide = math.random(1, 2)
- if randomSide == 2 then
- randomEndPosX = 1 - randomEndPosX
- end
- local endUDim2 = UDim2.new(randomEndPosX, 0, randomEndPosY, 0)
- if randomSide == 1 then
- newCircle.Position = UDim2.new(0, 0, 1, 0)
- else
- newCircle.Position = UDim2.new(1, 0, 1, 0)
- end
- local corner = Instance.new("UICorner")
- corner.Parent = newCircle
- corner.CornerRadius = UDim.new(1, 0)
- newCircle.BackgroundColor3 = Color3.new(randomColor, randomColor, randomColor)
- newCircle.Parent = library.loading.screen.LoadingScreen
- newCircle:TweenPosition(endUDim2, Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 3)
- coroutine.wrap(function()
- task.wait(3)
- newCircle:Destroy()
- end)()
- task.wait(0.15)
- end
- end)()
- for _, s in pairs(assets) do
- for n, a in pairs(s) do
- game.ContentProvider:PreloadAsync({a})
- count = count + 1
- -- print(count.."/"..totalCount)
- end
- end
- finishedLoading = true
- return "Loaded"
- end
- function loadController:init()
- end
- function loadController:KnitStart()
- cameraController = Knit.GetController("CameraController")
- uiController = Knit.GetController("UIController")
- islandService = Knit.GetService("IslandService")
- local timeCalled = tick()
- icon:WaitForChild("UIGradient").Color = ColorSequence.new{
- ColorSequenceKeypoint.new(0, c1),
- ColorSequenceKeypoint.new(0.999, c2),
- ColorSequenceKeypoint.new(1, c3)
- }
- icon.UIGradient.Offset = Vector2.new(0,-1)
- characterConnection = lPlr.CharacterAdded:Connect(function(char)
- if playClicked == false then
- char:FindFirstChild("Torso").Anchored = true
- else
- characterConnection:Disconnect()
- end
- end)
- loadController:initLoading()
- loadController:finishLoading()
- local timeFinished = tick()
- local totalCounted = timeFinished - timeCalled
- print("loadController initialized: took "..totalCounted.." seconds")
- end
- function loadController:KnitInit()
- loading.Enabled = true
- game.ContentProvider:PreloadAsync({icon})
- game.ContentProvider:PreloadAsync({library.loading.screen:WaitForChild("LoadingScreen")})
- end
- return loadController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement