Hello, I have been having issues with this one script. I did some prints, and it looks like it is not saving properly. Here is the script:
local DataStoreService = game:GetService("DataStoreService")
--DataStores
local CraftStore = DataStoreService:GetDataStore("CraftStore")
local InventoryStore = DataStoreService:GetDataStore("InventoryStore")
local ConstructionStore = DataStoreService:GetDataStore("ConstructionStore")
--Functions
game.Players.PlayerAdded:Connect(function(Player)
--Variables
local CraftExp = Instance.new("IntValue",Player)
local ConstructionExp = Instance.new("IntValue",Player)
local CraftMaxExp = Instance.new("IntValue",Player)
local ConstructionMaxExp = Instance.new("IntValue",Player)
local CraftLevel = Instance.new("IntValue",Player)
local ConstructionLevel = Instance.new("IntValue",Player)
local CraftSkillTable = CraftStore:GetAsync(Player.UserId) or {0,1,1}
local ConstructionSkillTable = ConstructionStore:GetAsync(Player.UserId) or {0,1,1}
local Inventory = InventoryStore:GetAsync(Player.UserId) or "Starter Axe"
for i,v in pairs(Inventory) do
print(v)
end
--Property Adjustments
CraftExp.Name = "CraftExp"
ConstructionExp.Name = "ConstructionExp"
CraftMaxExp.Name = "CraftMaxExp"
ConstructionMaxExp.Name = "ConstructionMaxExp"
CraftLevel.Name = "CraftLevel"
ConstructionLevel.Name = "ConstructionLevel"
CraftExp.Value = CraftSkillTable[1]
ConstructionExp.Value = ConstructionSkillTable[1]
CraftMaxExp.Value = CraftSkillTable[2]
ConstructionMaxExp.Value = ConstructionSkillTable[2]
CraftLevel.Value = CraftSkillTable[3]
ConstructionLevel.Value = ConstructionSkillTable[3]
--Load Inventory
for i,v in pairs(Player:WaitForChild("Backpack"):GetChildren()) do
if v.Name ~= "Starter Axe" then
v:Destroy()
end
end
for i,v in pairs(Inventory) do
if v ~= "Starter Axe" then
local Clone = game.ReplicatedStorage.Tools[v]:Clone()
Clone.Parent = Player.Backpack
end
end
--Value Changing
CraftExp:GetPropertyChangedSignal("Value"):Connect(function()
if CraftExp.Value > CraftMaxExp.Value then
CraftExp.Value = 0
CraftMaxExp.Value = CraftMaxExp.Value * 2
CraftLevel.Value = CraftLevel.Value + 1
end
end)
ConstructionExp:GetPropertyChangedSignal("Value"):Connect(function()
if ConstructionExp.Value > ConstructionMaxExp.Value then
ConstructionExp.Value = 0
ConstructionMaxExp.Value = ConstructionMaxExp * 2
ConstructionLevel.Value = ConstructionLevel + 1
end
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
--DataStore Saving
local CraftStoreTable = {Player.CraftExp.Value,Player.CraftMaxExp.Value,Player.CraftLevel.Value}
local InventoryStoreTable = {}
for i,v in pairs(Player.Backpack:GetChildren()) do
table.insert(InventoryStoreTable,v.Name)
print(v.Name)
end
local ConstructionStoreTable = {Player.ConstructionExp.Value,Player.ConstructionMaxExp.Value,Player.ConstructionLevel.Value}
for i,v in pairs(CraftStoreTable) do
print(v)
end
for i,v in pairs(InventoryStoreTable) do
print(v)
end
for i,v in pairs(ConstructionStoreTable) do
print(v)
end
CraftStore:SetAsync("user_"..Player.UserId,CraftStoreTable)
InventoryStore:SetAsync("user_"..Player.UserId,InventoryStoreTable)
ConstructionStore:SetAsync("user_"..Player.UserId,ConstructionStoreTable)
end)
The issue is when I rejoin the game, my items in the datastore aren't loading. This seems like an issue with it not saving properly, but I'm not exactly too sure.
