#how to make sure that parts are loaded on the players screen before teleporting them
1 messages · Page 1 of 1 (latest)
neccesary code -
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
ReplicatedFirst:RemoveDefaultLoadingScreen()
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local loadingScreen = script:WaitForChild("LoadingScreen"):Clone()
loadingScreen.Parent = playerGui
local frame = loadingScreen:WaitForChild("Background")
local loadingText = frame:WaitForChild("LoadedX")
local percent = frame:WaitForChild("Percent")
local classification = loadingScreen:WaitForChild("Classification")
local introsound = classification:WaitForChild("LoadingBackrooms")
local ding = game:WaitForChild("ReplicatedStorage"):WaitForChild("Sounds"):WaitForChild("ding")
local assets = game:GetChildren()
for i, asset in pairs(assets) do
task.wait(0.01)
loadingText.Parent = loadingScreen
loadingText.Text = "(".. i .. "/" .. #assets .. ") " .. " Loading " .. asset.Name
ContentProvider:PreloadAsync({asset})
ding:Play()
local progress = i / #assets
percent.Text = math.round(progress*100) .. "%"
end
local spawnedChunks = game.Workspace.LoadedChunks.Chunks:GetChildren()
local playerLoaded = game:WaitForChild("ReplicatedStorage"):WaitForChild("events"):WaitForChild("playerLoaded")
playerLoaded.OnClientEvent:Connect(function()
for i, spawnedChunk in pairs(spawnedChunks) do
task.wait(0.01)
loadingText.Parent = loadingScreen
loadingText.Text = "(".. i .. "/" .. #spawnedChunks .. ") " .. " Loading " .. spawnedChunk.Name
ContentProvider:PreloadAsync({spawnedChunk})
local progress = i / #spawnedChunks
percent.Text = math.round(progress*100) .. "%"
end
end)
loadingText.Text = "Loading Complete"
rest is just intro animation