Module script returns nothing in every script except the server handler script

Basically, I store and load my player’s currency data using module scripts inside of Replicated Storage. When a player joins, it’ll check the datastore if they have data yet or not, if not then set all the currency amount to 0. All of the code for this lies in my server handler in Server Script Service

The problem is that one day, it just broke for some reason. When I tried to require the player’s module script in the server handler and print it, it does print out the player’s existing data. But when I try to do the same thing for any other script in my game, it would just print an empty table. Here’s an example of the error I’m facing:

image
Here’s what prints out when the player joins the game, which is correct according to the player’s data


And here’s what prints out when I try to access it from anything but the server handler script

Even when writing this down and testing it again, now this problem also affected my player inventory module too. I have no idea on how to fix this issue. At first I thought it might be something to do with the pcall functions because I feel like the way I coded it, it doesn’t seem right. But I don’t know. Can someone please help me? Here’s the code in my server handler for when the player loads into the game:

 Players.PlayerAdded:Connect(function(player)	
 	player.CharacterAdded:Wait()
 	
 	local playerInventoryModule = InventoryTemplate:Clone()
 	playerInventoryModule.Name = player.UserId
 	playerInventoryModule.Parent = PlayerInventories
	playerInventoryModule = require(playerInventoryModule)
 	
 	local playerCurrencyModule = CurrencyTemplate:Clone()
 	playerCurrencyModule.Name = player.UserId
 	playerCurrencyModule.Parent = PlayerCurrencies
 	playerCurrencyModule = require(playerCurrencyModule)
 	
 	local success, inventory = pcall(function()
 		local rawData = PlayerInventory:GetAsync(player.UserId)
 		
 		if rawData then
 			local savedData = Hservice:JSONDecode(rawData)
 			
 			return savedData
 		else
 			return {}
 		end
 	end)
 	
 	if success then
 		playerInventoryModule["Inventory"] = inventory
 		
 		for itemName, item in pairs(inventory) do
 			local isSeed = repstore.Tools.Seeds:FindFirstChild(itemName)
 			
 			if isSeed then
 				local playerBackpack = player:WaitForChild("Backpack")
 				local clone = isSeed:Clone()
 				clone.Parent = playerBackpack
 				clone.Amount.Value = item.Amount
 				print(isSeed.Name)
 			end
 		end
 	end
 	
 	local success2, currency = pcall(function()
 		local rawData = PlayerCurrency:GetAsync(player.UserId)
 
		if rawData then
			local savedData = Hservice:JSONDecode(rawData)

			return savedData
 		else
			return {
 				Cash = {Amount = 0},
 				Gems = {Amount = 0}
 			}
 		end
 	end)
	
	if success2 then
 		playerCurrencyModule["Currency"] = currency
 	else
 		warn("Failed to load inventory!")
 	end
 	
 	print(require(PlayerInventories:WaitForChild(player.UserId)))
 	
 	print(require(PlayerCurrencies:WaitForChild(player.UserId)))
 end)
1 Like