When the player leaves, the session data with them stays. I’m not sure how to actually remove this without possibly erroring. When they rejoin, that data is overwritten by their datastore. The data module:
local aloe = {};
--// SERVICES \\
local DataStoreService = game:GetService("DataStoreService")
--// DATA VARS \\
local sessionData = {};
local dataSet = DataStoreService:GetDataStore("AloeV.13")
local RapSet = DataStoreService:GetOrderedDataStore('AloeV.5_Rap')
local startData = {
Values = {
Bux = 250000,
Tix = 0,
XP = 0,
Level = 0,
Gems = 0,
CasesOpen = 1,
Progress = 0,
Prestige = 1,
},
Arrays = {
Inventory = {},
Flags = {},
Equipped = {};
}
}
--// FUNCTIONS \\
local function recursiveCopy(dataTable)
local tableCopy = {}
for index, value in pairs(dataTable) do
if type(value) == "table" then
value = recursiveCopy(value)
end
tableCopy[index] = value
end
return tableCopy
end
aloe.post = function(player, body, title)
game.ReplicatedStorage.Notification:FireClient(player, body, title)
end
aloe.Get = function(value1)
return sessionData[value1];
end
local rewards = {};
aloe.AddReward = function(player, amount)
rewards[player] += amount
end
aloe.GetReward = function(player)
return rewards[player]
end
aloe.RAPCalculate = function(value1)
local inventory = sessionData[value1].Arrays.Inventory;
if not inventory then return 0 end
local rap = 0
for i, v in pairs(inventory) do
rap += v.Amount * v.Rap;
end
return rap;
end
aloe.StartServer = function(value1)
if dataSet:GetAsync(value1.UserId) then
sessionData[value1] = dataSet:GetAsync(value1.UserId)
else
sessionData[value1] = recursiveCopy(startData)
end
rewards[value1] = 0
end
aloe.Save = function(value1)
if not sessionData[value1].Arrays.Flags then
sessionData[value1].Arrays.Flags = {};
end
if not sessionData[value1].Values.Progress then
sessionData[value1].Values.Progress = 0
end
dataSet:SetAsync(value1.UserId, sessionData[value1])
RapSet:SetAsync(value1.Name .. ";" .. value1.UserId, aloe.RAPCalculate(value1))
end
aloe.GrabRap = function()
local globalData = {};
local page = RapSet:GetSortedAsync(false, 100);
page = page:GetCurrentPage();
for key, value in next, page do
globalData[#globalData + 1] = {value.key, value.value};
end
return globalData;
end
aloe.Flag = function(player, FlagReason, FlagTitle)
end
aloe.GiveItem = function(player, item2, Amount)
local item
local inventory = sessionData[player].Arrays.Inventory;
for i = 1, #inventory do
local v = inventory[i]
if v.ItemId == item2 then
v.Amount += Amount
return
end
end
local items = require(script.Parent.Items)
for i, v in pairs(items) do
if v.ItemId == item2 then
item = v
end
end
item.Amount = Amount;
inventory[#inventory + 1] = item;
end
aloe.CaseItem = function(player, item2, Amount)
local item
local inventory = sessionData[player].Arrays.Inventory;
for i = 1, #inventory do
local v = inventory[i]
if v.ItemId == item2.ItemId then
v.Amount += Amount
return
end
end
item2.Amount = Amount;
inventory[#inventory + 1] = item2;
end
aloe.RemoveItem = function(player, itemId, amount)
local inventory = sessionData[player].Arrays.Inventory;
if not itemId then return end
local buxToReturn = 0 -- This is only if selling and not jackpotting
for i, v in pairs(inventory) do
if v.ItemId == itemId then
if v.Locked == true then
buxToReturn = 0;
break
end
if v.Amount - amount == 0 then
buxToReturn = amount * v.Rap
table.remove(inventory, i);
break
end
if tonumber(v.Amount) > amount then
v.Amount -= amount;
buxToReturn = amount * v.Rap
break
end
end
end
local x = sessionData[player].Values.Prestige
if x == 1 then x = 1 else x = x * 5.75 end
return buxToReturn * x
end
aloe.Prestige = function(player)
local inventory = sessionData[player].Arrays.Inventory; -- BYPASSES LOCK
local prestigeItemCount = 0
for i, v in pairs(inventory) do
if inventory[i].ItemId == 140469106 then
prestigeItemCount += inventory[i].Amount
break
end
end
sessionData[player].Arrays.Inventory = {};
aloe.GiveItem(player, 140469106, prestigeItemCount)
end
aloe.SellAll = function(player)
local offset = 0;
local inventory = sessionData[player].Arrays.Inventory;
for index = 1, #inventory do
local item = inventory[index - offset];
if not item.Locked then
if item and item.Amount > 1 then
local averagePrice = aloe.RemoveItem(player, item.ItemId, item.Amount);
if averagePrice then
sessionData[player].Values.Bux = sessionData[player].Values.Bux + averagePrice;
end
else
local averagePrice = aloe.RemoveItem(player, item.ItemId, item.Amount);
if averagePrice then
sessionData[player].Values.Bux = sessionData[player].Values.Bux + averagePrice;
end
end
offset = offset + 1;
end
end
end
aloe.JackpotItem = function(player, itemId, amount)
local inventory = sessionData[player].Arrays.Inventory;
local doesHaveItem = false
if amount < 1 then
return false
end
for i, v in pairs(inventory) do
if v.ItemId == itemId then
if v.Locked == true then
doesHaveItem = false;
break
end
if v.Amount - amount == 0 then
doesHaveItem = true;
table.remove(inventory, i);
break
end
if tonumber(v.Amount) > amount then
v.Amount -= amount;
doesHaveItem = true;
break
end
end
end
return doesHaveItem;
end
return aloe;