I’m trying to make a loading screen, but when I test it out. It errors with “Unable to cast to array”.
Here’s the code
--[[
|| Script Name: Loading
|| Script Type: Executable
|| Written by: @NolanCYT
|| Version 1.0
|| Description: Loads the game
|| This LocalScript will create a ScreenGui to cover the game while all assets and data are loaded in.
|| To disable script, simply change the boolean "LoadGame" to false.
|| And vice versa to enable game loading.
]]
--[Data]
local t = true
local f = false
local LoadGame = t
--[Services]
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
--[Variables]
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local UserID = Player.UserId
local Assets = ReplicatedStorage:WaitForChild("Assets")
local Audio = require(Assets:WaitForChild("Audio"))
local DevProducts = require(Assets:WaitForChild("DevProducts"))
local Images = require(Assets:WaitForChild("Images"))
local Animations = require(Assets:WaitForChild("Animations"))
local Places = require(Assets:WaitForChild("Places"))
function create(instanceType)
return function(data)
local Object = Instance.new(instanceType)
for a, b in pairs(data) do
local c, d = pcall(function()
if type(a) == 'number' then b.Parent = Object
elseif type(b) == 'function' then Object[a]:connect(b)
else Object[a] = b end
end)
if not c then
error('ERROR: Applying property, '..a..', to '..instanceType..' failed! ('..d..')')
end
end
return Object
end
end
--[[
||Checkpoint #1
--
||Creating Loading GUI, Preloading Images and Audio
--]]
if LoadGame ~= t then script:Destroy() end
local Gui = Instance.new("ScreenGui")
Gui.Name = "LoadingGui"
Gui.IgnoreGuiInset = t
Gui.Parent = PlayerGui
local Background = create 'Frame' {
BackgroundColor3 = Color3.new(0, 0, 0),
BorderSizePixel = 0,
Size = UDim2.new(1.0,0,1.0,0),
Position = UDim2.new(0.0,0,0.0,0),
Parent = Gui
}
ReplicatedFirst:RemoveDefaultLoadingScreen()
--[Buffer]
task.wait(3)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,f)
local AssetNumber = create 'TextLabel' {
BackgroundTransparency = 1.0,
Size = UDim2.new(1.0,0,0.0,40),
Position = UDim2.new(0.0,0,0.0,40),
TextXAlignment = Enum.TextXAlignment.Left,
Font = Enum.Font.Arcade,
TextScaled = true,
TextColor3 = Color3.new(1, 1, 1),
ZIndex = 2,
Parent = Background,
}
--[Counting the Assets/Buffer]
local a = 1
for _, assets in pairs(Images) do
a = a + 1 AssetNumber.Text = ("("..a..")")
task.wait(math.random(0.01,0.06))
end
AssetNumber:Remove()
--[Buffer]
task.wait(1)
--[Load Images]
local function PreloadFailed(contentId,Status)
if Status == Enum.AssetFetchStatus.Failure then
error("Failed to load "..tostring(contentId))
end
end
local StatusLabel = create 'TextLabel' {
BackgroundTransparency = 1.0,
Size = UDim2.new(1.0,0,0.0,40),
Position = UDim2.new(0.0,0,0.0,40),
TextXAlignment = Enum.TextXAlignment.Left,
Font = Enum.Font.Arcade,
TextScaled = true,
TextColor3 = Color3.new(1, 1, 1),
ZIndex = 2,
Parent = Background,
}
--[Preload Images]
StatusLabel.Text = "Loading Images..."
for _, image in pairs(Images) do
ContentProvider:PreloadAsync(image,PreloadFailed)
end
--[Preload Audio]
StatusLabel.Text = "Loading Audio..."
for _, audio in pairs(Audio) do
ContentProvider:PreloadAsync(audio,PreloadFailed)
end
--[Preload Animations]
StatusLabel.Text = "Loading Animations..."
for _, animation in pairs(Animations) do
ContentProvider:PreloadAsync(animation,PreloadFailed)
end
The error is on this chunk of code:
--[Preload Images]
StatusLabel.Text = "Loading Images..."
for _, image in pairs(Images) do
ContentProvider:PreloadAsync(image,PreloadFailed)
end
Any help will do. Thanks!