i have a datastore module
local data = {}
local DatastoreService = game:GetService("DataStoreService")
local PlayerData = DatastoreService:GetDataStore("PlayerData")
--local setStats = require(script.setStats)
local defaultData = require(script.defaultData)
local dataTables = {}
local dataTableChanged = game:GetService("ServerStorage").dataTableChanged
print("hello?")
function data.start(player: Player)
local userData = PlayerData:GetAsync(player.UserId)
if not userData then
userData = defaultData
else
syncDataWithDefaults(userData, defaultData)
end
dataTables[player] = userData
print(dataTables[player])
return dataTables[player]
end
ok and in a script in serverscriptservice
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
CharacterInit:init(Character)
end)
dataModule.start(Player)
and it prints “hello?”
and then in a stat script
local Ego = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local dataModule = require(ServerStorage.Modules.Player.data)
function Ego.IncrementStat(player: Player, stat: string, amount, color)
local statx = dataModule.getData(player)
print(statx)
if amount >= 0 then
ReplicatedStorage.events.reward:FireClient(player, stat, amount, color, true)
elseif amount < 0 then
ReplicatedStorage.events.reward:FireClient(player, stat, amount, color, false)
end
dataModule.incrementData(player, stat, amount)
end
it prints “hello?” again AND it says nil because theres nothing in the dataTables table
??? what is happening why is it running twice