I want the user to upload and id and it saves forever in the game
for everytime they do it
You mean Save Data player?Do I understand you correctly?
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("DataStoreTable")
game.Players.PlayerAdded:Connect(function(player)
local tableOfData
local success, errormessage = pcall(function()
tableOfData = datastore:GetAsync(player.UserId)
end)
if success and tableOfData then
for key, value in pairs(tableOfData) do
print(key)
print(value)
player.UserId = tableOfData["PlayerID"]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local tableOfData = {
["PlayerID"] = player.UserId
}
local success, errormessage = pcall(function()
datastore:SetAsync(player.UserId, tableOfData)
end)
end)
Is that what you meant?
Yea and then theres a text box and that value saves but they can change it and it stores in a different value for example: player types “IMAGEID” and the id saves and if they do it again both of them save
so that you will have 2 values
Use FireServer() , in the server script use OnServerEvent and pairs to table these values
local FireServer = game.ReplicateStorage.FireServer -- path of your event
FireServer.OnServerEvent:Connect(function(player)
Local Folder = player.Folder --this is the place where the data will be stored
local ImageId = -Instance.new("NumberValue", Folder)
ImageId.Name = --path to TextBox.Text
end
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("DataStoreTable")
game.Players.PlayerAdded:Connect(function(player)
local tableOfData
local ImageIDTable = {}
local success, errormessage = pcall(function()
tableOfData = datastore:GetAsync(player.UserId)
end)
if success and tableOfData then
for key, value in pairs(tableOfData) do
print(key)
print(value)
ImageIDTable = tableOfData["ImageID"]
end
if ImageIDTable == nil then
else
for i, v in ipairs(ImageIDTable) do
print(v) -- i don't know where you have to put your id
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ImageIDTable = {}
for i, v in ipairs(player.Folder:GetChildren()) do
table.insert(ImageIDTable, v.Name)
end
local tableOfData = {
["ImageID"] = ImageIDTable
}
local success, errormessage = pcall(function()
datastore:SetAsync(player.UserId, tableOfData)
end)
end)
The script may have errors as it is written on the website (i.e. here)
i know but is there a way to like save multiple values from one id
If you want to save multiple values, put all the values in a table and save the table.
But the player makes more its an uploading system so i cant add the value if the player makes it