So I made a module script for inventories to make it easier for me & I am trying to use datastore in the module script to save & load inventories but when I try to test it it just comes up with the error "DataStore can't be accessed from client". I looked around but I couldn't find anything saying you couldn't access DataStore from a module script but I still don't know why this error comes up, here is the code (without the parts that don't access datastore):
local InventoryMod = {}
DataStoreService = game:GetService("DataStoreService")
InventoryStore = DataStoreService:GetDataStore("InventoryDataStore")
Refresh = game.StarterGui.ScreenGui.Inventory.Refresh
Inventories = {}
function InventoryMod.LoadInventory(player)
Inventories[player.name] = InventoryStore:GetAsync(player.UserId)
if Inventories[player.name] == nil then
Inventories[player.name] = InventoryMod.NewInventory(player)
end
Refresh:FireClient(player)
end
function InventoryMod.SaveInventory(player)
if Inventories[player.name] ~= nil then
InventoryStore:SetAsync(player.UserId, Inventories[player.name])
end
end
function InventoryMod.PlayerLeaving(player)
InventoryMod.SaveInventory(player)
Inventories[player.name] = nil
end
return InventoryMod
BTW Refresh is the remote event that I use to tell the inventory GUI script to refresh & InventoryMod.NewInventory is the function to make a new inventory with some items.
