I'm new to Roblox scripting and used a tutorial to make an inventory system. It works fine but when you leave and rejoin it doesn't save. I've tried to make my own datastore and it's not working. I can't find any tutorials. Please help me.
local DSS = game:GetService("DataStoreService")
local inventory = DSS:GetDataStore("inventory")
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Inventory = game.Players.LocalPlayer.Inventory
local Wood = Inventory.Wood
local Leaves = Inventory.Leaves
local Stone = Inventory.Stone
Wood.Value = inventory:GetAsync(Player.userId) or 0
Leaves.Value = inventory:GetAsync(Player.userId) or 0
Stone.Value = inventory:GetAsync(Player.userId) or 0
game.Players.PlayerRemoving:connect(function(Player)
inventory:SetAsync(Player.userId, Wood.Value)
inventory:SetAsync(Player.userId, Leaves.Value)
inventory:SetAsync(Player.userId, Stone.Value)
end)
while true do
wait(20)
inventory:SetAsync(Player.userId, Wood.Value)
inventory:SetAsync(Player.userId, Leaves.Value)
inventory:SetAsync(Player.userId, Stone.Value)
end
end)
end)
The 3 values I want to save are under Players, [everyone], Inventory, then the three int values.
