So, basically I want to make an inventory system that uses data stores to save
But the problem is that I dont know where to store it actually without using leaderstats
I tried to use Module Scripts but how can I create a new module for each player everytime he joins?
Also, I need to send that data to the local player, so I can add invenory items from data to inventory gui
Im actually sending the data firing a remote event that contains player’s data
game.Players.PlayerAdded:Connect(function(player)
----------------------------
local playerKey = "Player"..player.UserId.." Data"
----------------------------
local Data
local succes, errormessage = pcall(function()
Data = PlayersData:GetAsync(playerKey)
end)
if succes then
if Data then
print(Data)
else
Data = {
OwnedColors = {"Really black", "Burnt Sienna", "Lime green","Dark grey","Really blue", "New Yeller","Institutional white", "Really Red", "Magenta"},
OwnedMaterials = {"Plastic", "Granite", "Concrete", "Foil","Slate","Wood"}
}
print(Data," Player has no data, giving some")
end
SendDataEvent:FireClient(player,Data)
end
This works for now, but when the player leaves I have no source to get the data back and save it
game.Players.PlayerRemoving:Connect(function(player)
local playerKey = "Player"..player.UserId.." Data"
PlayersData:SetAsync(playerKey, Data) -- There's no data variable, I have no source to get it
end)
So, I tried to connect that PlayerRemoving function inside the PlayerAdded
game.Players.PlayerAdded:Connect(function(player)
----------------------------
local playerKey = "Player"..player.UserId.." Data"
----------------------------'''''
local Data
local succes, errormessage = pcall(function()
Data = PlayersData:GetAsync(playerKey)
end)
if succes then
if Data then
print("Player has data!")
print(Data)
else
Data = {
OwnedColors = {"Really black", "Burnt Sienna", "Lime green","Dark grey","Really blue", "New Yeller","Institutional white", "Really Red", "Magenta"},
OwnedMaterials = {"Plastic", "Granite", "Concrete", "Foil","Slate","Wood"}
}
print(Data," Player has no data, giving some")
end
SendDataEvent:FireClient(player,Data)
end
game.Players.PlayerRemoving:Connect(function(player)
PlayersData:SetAsync(playerKey, Data)
end)
end)
So now I have a data variable with player removing, but the problem now is that when I add some data to a player it changes for everyone in the server