Requested module experienced an error while loading

Local:

local ToolsManager = require(game.ReplicatedStorage.toolsManager)


Module:

wait(0.3)
local ToolsManager = {}

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local ServerScriptService = game:GetService("ServerScriptService")
--local Workspace = game:GetService("Workspace")

local DataStore2 = require(ServerScriptService.DataStore2)

DataStore2.Combine("DATA", "warehouse", "backpack", "hand")

function ToolsManager.buy(toolName)
	local warehouseStore = DataStore2("warehouse", player)
	local warehouseTools = warehouseStore:Get({})
	warehouseTools.insert(toolName)
	warehouseStore:Set(warehouseTools)
	print("Buy "..toolName)
end

return ToolsManager

so why, then I get this error: although I just want to get a modular script

Looking above, I saw that I have the following error above:
DataStore2 is not a valid member of ServerScriptService “ServerScriptService”

local DataStore2 = require(ServerScriptService.DataStore2)

that is, there I can’t get another modular script. So I explain the final situation in the module script, I get the module script and get it locally, but I get an error, why?

1 Like

Little bit confused on what you’re asking, but I’ll try my best to help!

You get the error that you’re getting because you’re running the ModuleScript from inside a LocalScript. It needs to be ran from a server sided script before it will be able to see any objects inside of ServerScriptService & ServerStorage.

2 Likes

I just want to create the universal script to use from my local scripts to get rid of the code duplicating.

1 Like

It"s because of this! You can’t use a client-only object with a server-locked service, if you wanna access localplayer only use it on functions you’re requiring the module from localscripts.

1 Like

ok, got it. thanks for your help

1 Like

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