I'm actually working on a project, but right on the first system, I had a frustrating problem and according to the logic, I'm pretty sure it's impossible. Every players have the same stastics. So, I guessed it was maybe the script sending the table to clients that was making failure. But, by adding a repetition, which was always returning the statistics of all the players, I noticed that my ModuleScript was changing all the statistics of all the players at the same time. Here's a GIFF of this repetition. So, the problem come from my ModuleScript "DataManager". I don't understand how this error can even be possible. I put the script down below. i'm not really expecting answers but I hope someone will know what is the problem and will tell me because it's really frustrating to work on a system that doesn't even work and with a "invisible" error...
local DataManager = {}
--< Services
local PlayerService = game:GetService('Players')
local RStorageService = game:GetService('ReplicatedStorage')
--< Relative game variables
local SessionData = {}
local StartData = {Level = 1, Money = 0, Experience1 = 0, Experience2 = 400, Language = 1}
--< Links game variables
local Events = RStorageService.Events
local UpdateData = Events.UpdateData
--< Usable module functions
local function SetupPlayerData(Player)
SessionData[Player] = StartData
end
local function CheckExperience(Player)
if SessionData[Player]['Experience1'] >= SessionData[Player]['Experience2'] then
SessionData[Player]['Experience1'] = math.floor(SessionData[Player]['Experience1'] - SessionData[Player]['Experience2'])
SessionData[Player]['Experience2'] = math.floor(SessionData[Player]['Experience2'] / 1.5 + 100 * (SessionData[Player]['Experience2'] / 20 * 0.02) + 215)
SessionData[Player]['Level'] = SessionData[Player]['Level'] + 1
SessionData[Player]['Money'] = SessionData[Player]['Money'] + (SessionData[Player]['Level']* 0.1 * 10)
end
end
--< Usable game functions
function DataManager:PlayerDataUpdate(Player)
UpdateData:FireClient(Player, SessionData[Player])
end
function DataManager:ChangeStat(Player, isLanguage, isStat, Value, Stat, Any)
if isLanguage then
SessionData[Player]['Language'] = Value
elseif isStat then
if Any then
SessionData[Player][Stat] = SessionData[Player][Stat] + Value
else
SessionData[Player][Stat] = SessionData[Player][Stat] - Value
end
end
CheckExperience(Player)
DataManager:PlayerDataUpdate(Player)
end
function DataManager:GetStat(Player, Stat)
return SessionData[Player][Stat]
end
--< Events
PlayerService.PlayerAdded:Connect(SetupPlayerData)
return DataManager
