It only saves the names of the keys without their values ({HasPlayed} instead of {HasPlayed} = true
this is the module function for when a value changes
function playerModule:ValueChanged(player, value)
print("module script")
print(playerModule[player.Name])
table.insert(playerModule[player.Name], value.Name)
task.wait()
playerModule[player.Name][value.Name] = value.Value
print("added to table!")
print(playerModule.toUpdate)
end
server script save function:
function dataSave(player)
print(moduleScript[player.Name]) --- this prints {HasPlayed} = true, [1]HasPlayed
local playerTable = moduleScript[player.Name]
local success, err = pcall(function()
mystore:SetAsync(player.UserId .. "_" .. key, playerTable)
end)
if success then
print("data saved!")
if not player then
local updateModule = require(game.ReplicatedStorage:FindFirstChild("UpdateData"))
task.wait()
table.clear(moduleScript[player.Name])
print("table cleared!")
else
local updateModule = require(game.ReplicatedStorage:FindFirstChild("UpdateData"))
task.wait()
table.clear(moduleScript[player.Name])
print("table cleared!")
local GetPlayerData = mystore:GetAsync(player.UserId .. "_" .. key)
print(GetPlayerData) --- supposed to print same as first print, but instead prints {HasPlayed}
end
else
print("data failed to save..." .. err)
end
end
Yes so I actually fixed that, but now it only saves the names of the keys without their values ({HasPlayed} instead of {HasPlayed} = true
this is the module function for when a value changes
function playerModule:ValueChanged(player, value)
print("module script")
print(playerModule[player.Name])
table.insert(playerModule[player.Name], value.Name)
task.wait()
playerModule[player.Name][value.Name] = value.Value
print("added to table!")
print(playerModule.toUpdate)
end
server script save function:
function dataSave(player)
print(moduleScript[player.Name]) --- this prints {HasPlayed} = true, [1]HasPlayed
local playerTable = moduleScript[player.Name]
local success, err = pcall(function()
mystore:SetAsync(player.UserId .. "_" .. key, playerTable)
end)
if success then
print("data saved!")
if not player then
local updateModule = require(game.ReplicatedStorage:FindFirstChild("UpdateData"))
task.wait()
table.clear(moduleScript[player.Name])
print("table cleared!")
else
local updateModule = require(game.ReplicatedStorage:FindFirstChild("UpdateData"))
task.wait()
table.clear(moduleScript[player.Name])
print("table cleared!")
local GetPlayerData = mystore:GetAsync(player.UserId .. "_" .. key)
print(GetPlayerData) --- supposed to print same as first print, but instead prints {HasPlayed}
end
else
print("data failed to save..." .. err)
end
end
In playerModule:ValueChanged, you use table.insert which is generally for arrays. When you use table.insert, it adds the value at the end of the array, but you are also setting playerModule[player.Name][value.Name] which is more appropriate for dictionary-like tables.
Here
function playerModule:ValueChanged(player, value)
print("module script")
print(playerModule[player.Name])
playerModule[player.Name][value.Name] = value.Value
print("added to table!")
print(playerModule.toUpdate)
end
function dataSave(player)
print(moduleScript[player.Name]) --- this prints {HasPlayed} = true, [1]HasPlayed
local playerTable = moduleScript[player.Name]
-- Print table contents to debug
for k, v in pairs(playerTable) do
print(k, v)
end
local success, err = pcall(function()
mystore:SetAsync(player.UserId .. "_" .. key, playerTable)
end)
if success then
print("data saved!")
if not player then
local updateModule = require(game.ReplicatedStorage:FindFirstChild("UpdateData"))
task.wait()
table.clear(moduleScript[player.Name])
print("table cleared!")
else
local updateModule = require(game.ReplicatedStorage:FindFirstChild("UpdateData"))
task.wait()
table.clear(moduleScript[player.Name])
print("table cleared!")
local GetPlayerData = mystore:GetAsync(player.UserId .. "_" .. key)
-- Print fetched data to debug
for k, v in pairs(GetPlayerData) do
print(k, v)
end
print(GetPlayerData) --- supposed to print same as first print, but instead prints {HasPlayed}
end
else
print("data failed to save..." .. err)
end
end