"Attempt to Index nil with [module]"?

Hello! I’ve been working on a new project and I’m making a loading script in ReplicatedFirst. But I’ve encountered an issue when trying to preload the images in the script.

Here is the error I encounter.
Screenshot_20221229_021428

It says “Attempt to Index nil with Images” even thought the module is there.

Here is the ServerStorage:
Screenshot_20221229_021755

Here is the script.

--[[
	|| 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.
	
	|| Required Modules:
		Images
]]

--[Data]
local t = true
local f = false

--[Services]
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ServerStorage = game:GetService("ServerStorage")

--[Variables]
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local UserID = Player.UserId

local Assets = ServerStorage:FindFirstChild("Assets")
local Images = require(Assets.Images)

--[Create Function]
function create(InstanceData)
	return function(data)
		local obj = Instance.new(InstanceData)
		for a, b in pairs(data) do
			local c, d = pcall(function()
				if type(a) == 'number' then b.Parent = obj
				elseif type(b) == 'function' then obj[a]:connect(b)
				else obj[a] = b end
			end)
			if not c then
				error('ERROR: Applying the property, '..a..', to '..InstanceData..', Failed! ('..d..')', 2.0)
			end
		end
		return obj
	end
end

--[[
	||Checkpoint #1
	--
	||Creating Loading GUI and Preloading Images
--]]

local Gui = Instance.new("ScreenGui")
Gui.Name = "LoadingGui"
Gui.IgnoreGuiInset = t
Gui.Parent = PlayerGui

local Background = create 'Frame' {
	BackgroundColor3 = Color3.new(0.0, 0.0, 0.0),
	BorderSizePixel = 0.0,
	Size = UDim2.new(1.0,0,1.0,0),
	Position = UDim2.new(0.0,0,0.0,0),
	Parent = Gui
}

ReplicatedFirst:RemoveDefaultLoadingScreen()
local function PreloadFailed(contentId, Status)
	if Status == Enum.AssetFetchStatus.Failure then
		error("Failed to load", contentId)
	end
end
ContentProvider:PreloadAsync(Images, PreloadFailed)

local Checkpoint1 = create 'ImageLabel' {
	BackgroundTransparency = 0.0,
	Image = Images.LoadingIcon,
	Size = UDim2.new(0.0, 1, 0.0, 1),
	Position = UDim2.new(0.1, 0, 0.5, 0),
	Parent = Background,
}

I apologize if this was not spoken clearly enough. But please, if anybody could help I very much need it! Thank you!

1 Like

Is the loading script a LocalScript? Local scripts do not have access to ServerStorage

Yes, the loading script is local. Where should I move the Assets folder so the local script can have access to the modules?

If you put the Assets folder in ReplicatedStorage or ReplicatedFirst, local scripts will have access to it. These storages are replicated to the client

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.