Hey everyone, I have never posted on this site before but I can’t find the solution to a problem I’ve been having. Previously I have been handling session data with a physical structure (folders and values) but I want to move on to using modules instead. This has nothing to do with data stores, its purely the module itself that’s giving me trouble. The code itself works fine - I based it off of the example they had on the wiki here: Documentation - Roblox Creator Hub. The issue is that whenever I save new data to the module, it somehow replicates that to every individual table for each player in the game. So if I set playerData[player.Name][key] = 1, then every player.Name table will have “key” set to 1. I’ve tried messing around with print lines to see if its setting multiple times but it appears to only be doing it once. If anyone has any ideas of what I can try that would be much appreciated. I’ll post the code below as well if that helps. Thanks!
--Services
local repStorage = game:GetService("ReplicatedStorage")
--Data Components
local events = repStorage:WaitForChild("Events")
--Modules
local mod_DefaultPlayer = require(script.DefaultPlayer)
local mod_Keybinds = require(script.Keybinds)
--Events
local rem_Data = events:WaitForChild("Data")
--Variables
local module, playerData = {}, {}
--Functions
function printAll() --For Debugging
print("ALL DATA:")
for i, v in pairs(playerData) do
print(i)
for e, x in pairs(v) do
if type(x) == "table" then
print(" [table]")
else
print(" "..e.." = "..x)
end
end
end
end
--API
function module:Create(player)
--print("Creating data for "..player.Name)
if not playerData[player.Name] then
playerData[player.Name] = mod_DefaultPlayer.new() --Another workaround I tried
playerData[player.Name]["Keybinds"] = mod_Keybinds
--Add inventories and such
rem_Data:FireClient(player)
end
end
function module:Remove(player)
if playerData[player.Name] then
playerData[player.Name] = nil
end
end
function module:Get(player,key)
--print("Requesting: "..player.Name.. " "..key)
--printAll()
if key then
return playerData[player.Name][key]
else
return playerData[player.Name]
end
end
function module:Set(player,key,value)
print("Requesting: "..player.Name.. " "..key.. " = "..value)
playerData[player.Name][key] = value --HERE: This seems to set every player's key to value
rem_Data:FireClient(player) --Just informing the client
end
return module