I got this datastore script working fine, it saves everyone's stats and everything i have in the table but the "Stats" table i got in there only saves in the local side of roblox so when you click play in studio.
I'm saving a table and putting that table into another module so local scripts can read it and get information from it, that might be the problem i don't know.
In the server script i'm setting ClientStatCache
table to ClientStatCache[player]
so i know which players have which stats and i'm adding the table i'm saving in the datastore script into that module table.
Like i said it works in studio but not in game, it might have something to do with the localscript grabbing the player table from the module cause it dosen't seem to exist. It prints nil
when i print ClientStatCache[player].
I'm not getting any errors.
Datastore module script:
function SetupPlayerData(player) local success, data = LoadData(player) local function ReturnOwned() for i,v in pairs(ToolData) do end end ReturnOwned() if not success then PlayerData[player] = false else if not data then print("Save not found, creating a new save!") PlayerData[player] = { Cash = 0, Level = 1, Experience = 0, Rebirth = 0, Rank = "Beginner", Tool = "Trident", Backpack = "Backpack1", BackpackAmount = 0, Stats = { Quests = { Active = {}, Completed = {}, }, Totals = { Souls = { ["Bob's Adventure"] = { Harvested = 0, }, All = 0, } } } } savePlayerData(player) else PlayerData[player] = data end end end
Server script:
local ClientStatCache = require(game.ReplicatedStorage.ClientStatCache) ClientStatCache[player] = {} table.insert(ClientStatCache[player], PlayerData[player]["Stats"])
Client script:
local ClientStatCache = require(game.ReplicatedStorage.ClientStatCache) --Quests:Create(require(qqFolder["Bob's Adventure"])) local Stats repeat wait() until ClientStatCache[player] and ClientStatCache[player] ~= nil and ClientStatCache[player] Stats = ClientStatCache[player][1] print("Day Completed")
When you require a ModuleScript
, it runs its contents on the peer it was required on. ModuleScripts are cached per peer, not per game.
In other words, the module is sorta separate to all peers, so server and players.
Not to mention that if it actually worked, it would be insecure because exploiters could just append their own values to the table.