Hi Im trying to break down this script that I found on youtube and im confused about one part and its this part GetAsync("User-"..player.UserId) could someone please also explain what "Waters" is equal
here is the full script if you need it
local DataStoreService = game:GetService("DataStoreService")
local collected = DataStoreService:GetDataStore("collected")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WaterList = ReplicatedStorage:WaitForChild("Waterbottles")
game.Players.PlayerAdded:Connect(function(player)
local WaterCollected = Instance.new("Folder",player)
WaterCollected.Name = "WaterGettingColder"
local success, errormessage = pcall(function()
local water = collected:GetAsync("User-"..player.UserId)
if water then
for i, v in pairs(water) do
local waterfound = WaterList:FindFirstChild(v)
if waterfound then
waterfound:Clone().Parent = WaterCollected
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
local collectedsave = {}
for i, waters in pairs(player.WatereCollect:GetChildren()) do
if waters then
table.insert(collectedsave,waters.Name)
end
end
collected:SetAsync("User-"..player.UserId,collectedsave)
end)
end)
game:BindToClose(function(player)
local success, errormessage = pcall(function()
local collectedsave = {}
for i, waters in pairs(player.WatereCollect:GetChildren()) do
if waters then
table.insert(collectedsave,waters.Name)
end
end
collected:SetAsync("User-"..player.UserId,collectedsave)
end)
end)

1 comment
GetAsync gets data from the datastore, so basically it retrieves the data. The string inside "GetAsync" is what file is being retrieved. SetAsync sets the data so that next time when you join, GetAsync will get that data.