So yeah, currently im asking very often about saving and this stuff and heres on more question,
is it even possible to get every player who ever played the game to an variable or who has a special value:
local Plr = [GetAllPlayer(please correct this)]
if Plr.leaderstats:FindFirstChild("Played") then
--my action not important
end
ik my question is pretty odd, but it will help me, thank you!
I think you can create a table then use
game.Players.PlayerAdded:Connect()
to insert the players userid upon joining and save that table to a datastore?
not 100% sure if this works cuz im also new
--Normal script in serverscript service
game.Players.PlayerAdded:Connect(function (plr)
local DataStoreService = game:GetService("DataStoreService"):GetDataStore("PlrSave")
DataStoreService:SetAsynch("Key",plr.UserId)
end)
That breaks the script and will only save for last player, you even spelt SetAsync incorrectly
You can try this method (note: might not save if multiple servers try to access the data at the same time, consider using DataStore2 or ProfileService if this bothers you):
local data = game:GetService("DataStoreService"):GetDataStore("PlrSave")
game.Players.PlayerAdded:Connect(function(plr)
local plrTable
local s, e = pcall(function()
plrTable = data:GetAsync("Key") -- get table
end)
if not s then warn("retrieving data failed, reason: "..e) return end -- error
table.insert(plrTable, plr.UserId) -- insert userId
local s1, e1 = pcall(function()
data:SetAsync("Key", plrTable) -- set table
end)
if not s1 then warn("setting data failed, reason: "..e1) return end -- error
end)