KeepStore:andThen(function(store)
KeepStore = store
Players.PlayerAdded:Connect(onPlayerJoin)
end)
Error:
13:31:43.145 ServerScriptService.StatStuff:126: attempt to call missing method 'andThen' of table - Server - StatStuff:126
13:31:43.145 Stack Begin - Studio
13:31:43.145 Script 'ServerScriptService.StatStuff', Line 126 - Studio - StatStuff:126
13:31:43.145 Stack End - Studio
How do you do WriteLibs? I checked the source code, and found 0 mention of them, and when I do KeepService.WriteLib, it tells me “Cannot add property ‘WriteLib’ to table ‘Store’”.
StatManager
local Players = game:GetService("Players")
local KeepService = require(game.ReplicatedStorage.datakeep)
KeepService.WriteLib = require(game.ReplicatedStorage.WriteLib)
local DefaultData = {
Player = {
Lang = "English";
Lazercards = 0;
OwnedGuns = {"StarterPistol"};
EquippedGun = "StarterPistol";
Victories = 0;
Cosmeticards = 0;
ShirtID = 6536782130;
PantsID = 129459077;
R = .75;
G = .75;
B = .75;
OwnedShirts = {6536782130};
OwnedPants = {129459077};
Banned = false,
}
}
local KeepStore = KeepService.GetStore("PlayerData", DefaultData)
local LoadedKeeps = {}
local function onPlayerJoin(player)
KeepStore:LoadKeep("Player_" .. player.UserId):andThen(function(keep)
if keep == nil then
player:Kick("Data locked") -- will never happen, when no releaseHandler is passed it default steals from the locked session
end
keep:Reconcile()
keep:AddUserId(player.UserId) -- help with GDPR requests
keep.OnRelease:Connect(function() -- don't have to clean up, it cleans up internally.
player:Kick("Session Release")
end)
if not player:IsDescendantOf(Players) then
keep:Release()
return
end
local PlayerData = keep.Data
for i, v in pairs(DefaultData.Player) do
if PlayerData[i] == nil then
PlayerData[i] = v
end
end
print(keep)
print(PlayerData)
print(`Loaded {player.Name}'s Keep!`)
LoadedKeeps[player] = keep
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Lazercards = Instance.new("IntValue")
Lazercards.Name = "Lazercards"
Lazercards.Parent = leaderstats
Lazercards.Value = PlayerData.Lazercards
local Cosmeticards = Instance.new("IntValue")
Cosmeticards.Name = "Cosmeticards"
Cosmeticards.Parent = leaderstats
Cosmeticards.Value = PlayerData.Cosmeticards
local Tags = Instance.new("IntValue")
Tags.Name = "Tags"
Tags.Parent = leaderstats
Tags.Value = PlayerData.Tags
local Victories = Instance.new("IntValue")
Victories.Name = "Victories"
Victories.Parent = leaderstats
Victories.Value = PlayerData.Victories
end)
end
Players.PlayerRemoving:Connect(function(player)
local keep = LoadedKeeps[player]
if keep then return end
keep:Release()
end)
KeepStore:andThen(function(store)
KeepStore = store
Players.PlayerAdded:Connect(onPlayerJoin)
end)
local DataManager = {}
function DataManager:Get(player)
local keep = LoadedKeeps[player]
if keep then
local PlayerData = keep.Data
return PlayerData
end
end
return DataManager
The WriteLib
return {
SetLazercards = function(keep, amount)
keep.Data.Lazercards = amount
end,
SetCosmeticards = function(keep, amount)
keep.Data.Cosmeticards = amount
end,
SetEquippedGun = function(keep, gun)
keep.Data.EquippedGun = gun
end,
SetOwnedGuns = function(keep, Table)
keep.Data.OwnedGuns = Table
end,
SetLang = function(keep, lang)
keep.Data.Lang = lang
end,
SetVictories = function(keep, amount)
keep.Data.Victories = amount
end,
SetBanned = function(keep, bool)
keep.Data.Banned = bool
end,
SetCloth = function(keep, clothing, item)
if clothing == "Shirt" then
keep.Data.EquippedShirt = item
elseif clothing == "Pants" then
keep.Data.EquippedPants = item
end
end,
SetSkinRGB = function(keep, color, value)
if color == "R" then
keep.Data.R = value
elseif color == "G" then
keep.Data.G = value
else
keep.Data.B = value
end
end,
SetOwnedClothes = function(keep, clothing, Table)
if clothing == "Shirt" then
keep.Data.OwnedShirts = Table
elseif clothing == "Pants" then
keep.Data.OwnedPants = Table
end
end,
}
local Players = game:GetService("Players")
local KeepService = require(game.ReplicatedStorage.datakeep)
local DefaultData = {
Player = {
Lang = "English";
Lazercards = 0;
OwnedGuns = {"StarterPistol"};
EquippedGun = "StarterPistol";
Victories = 0;
Cosmeticards = 0;
ShirtID = 6536782130;
PantsID = 129459077;
R = .75;
G = .75;
B = .75;
OwnedShirts = {6536782130};
OwnedPants = {129459077};
Banned = false,
}
}
local KeepStore = KeepService.GetStore("PlayerData", DefaultData)
KeepStore.Wrapper = require(game.ReplicatedStorage.WriteLib)
local LoadedKeeps = {}
local function onPlayerJoin(player)
KeepStore:LoadKeep("Player_" .. player.UserId):andThen(function(keep)
if keep == nil then
player:Kick("Data locked") -- will never happen, when no releaseHandler is passed it default steals from the locked session
end
keep:Reconcile()
keep:AddUserId(player.UserId) -- help with GDPR requests
keep.OnRelease:Connect(function() -- don't have to clean up, it cleans up internally.
player:Kick("Session Release")
end)
if not player:IsDescendantOf(Players) then
keep:Release()
return
end
local PlayerData = keep.Data
for i, v in pairs(DefaultData.Player) do
if PlayerData[i] == nil then
PlayerData[i] = v
end
end
print(keep)
print(PlayerData)
print(`Loaded {player.Name}'s Keep!`)
LoadedKeeps[player] = keep
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Lazercards = Instance.new("IntValue")
Lazercards.Name = "Lazercards"
Lazercards.Parent = leaderstats
Lazercards.Value = PlayerData.Lazercards
local Cosmeticards = Instance.new("IntValue")
Cosmeticards.Name = "Cosmeticards"
Cosmeticards.Parent = leaderstats
Cosmeticards.Value = PlayerData.Cosmeticards
local Tags = Instance.new("IntValue")
Tags.Name = "Tags"
Tags.Parent = leaderstats
Tags.Value = PlayerData.Tags
local Victories = Instance.new("IntValue")
Victories.Name = "Victories"
Victories.Parent = leaderstats
Victories.Value = PlayerData.Victories
end)
end
Players.PlayerRemoving:Connect(function(player)
local keep = LoadedKeeps[player]
if keep then return end
keep:Release()
end)
KeepStore:andThen(function(store)
KeepStore = store
Players.PlayerAdded:Connect(onPlayerJoin)
end)
local DataManager = {}
function DataManager:Get(player)
local keep = LoadedKeeps[player]
if keep then
local PlayerData = keep
return PlayerData
end
end
return DataManager
GunManager
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StatManager = require(ReplicatedStorage.StatManager)
local GunStats = require(ReplicatedStorage.GunStats)
local ReplicatedEvents = ReplicatedStorage.Events.Replicated
local BuyGun = ReplicatedEvents.BuyGun
local GetGuns = ReplicatedEvents.GetGuns
local GetGun = ReplicatedEvents.GetGun
local SetGun = ReplicatedEvents.SetGun
local Guns = ReplicatedStorage:WaitForChild("Guns")
BuyGun.OnServerInvoke = function(Player, Gun)
local keep = StatManager:Get(Player)
print(keep.Data)
if keep.Data then
local MockTable = keep.Data.OwnedGuns
if keep.Data.Lazercards >= GunStats.Guns[Gun]["Price"] then
keep:SetLazercards(keep.Data.Lazercards - GunStats.Guns[Gun]["Price"])
table.insert(MockTable, Gun)
keep:SetOwnedGuns(MockTable)
return true
else
return false
end
else
return false
end
end
SetGun.OnServerInvoke = function(Player, Gun)
local keep = StatManager:Get(Player)
--print(keep.Data)
if keep.Data then
if table.find(keep.Data.OwnedGuns, Gun) then
keep:SetEquippedGun(Gun)
return true
else
return false
end
else
return false
end
end
GetGuns.OnServerInvoke = function(Player, Type)
local keep = StatManager:Get(Player)
print(keep.Data.OwnedGuns)
print(Type)
local GunsToReturn = {}
pcall(function()
if keep.Data then
if Type == "Owned" then
GunsToReturn = keep.Data.OwnedGuns
elseif Type == "Store" then
print("Getting store guns")
for i, v in pairs(Guns:GetChildren()) do
print("Checking "..v.Name)
if not table.find(keep.Data.OwnedGuns, v.Name) then
print(v.Name)
table.insert(GunsToReturn, v.Name)
end
end
end
end
end)
if #GunsToReturn > 0 then
return GunsToReturn
else
return false
end
end
GetGun.OnServerInvoke = function(Player)
local keep = StatManager:Get(Player)
print(keep.Data.EquippedGun)
local Item
pcall(function()
if keep.Data then
Item = Guns:WaitForChild(keep.Data.EquippedGun)
end
end)
if Item ~= nil then
return Item.Name
else
return false
end
end