Hello there.
I am not the best with Data stores as I didn’t use them often until now. I am trying to save multiple values in a folder at once.
local DataService = game:GetService("DataStoreService")
local DataStore = DataService:GetDataStore("PlayerInfo")
game.Players.PlayerAdded:Connect(function(Player)
local stats = Instance.new("Folder")
stats.Parent = game.ReplicatedStorage.PlayerInfo
stats.Name = Player.Name.."Data"
local GameStarted = Instance.new("BoolValue")
GameStarted.Name = "HasPlayed"
GameStarted.Parent = stats
local CharacterName = Instance.new("StringValue")
CharacterName.Name = "CharacterName"
CharacterName.Parent = stats
local playerUserId = "Player_"..Player.UserId
local Data
local success, errormessage = pcall(function()
Data = DataStore:GetAsync(playerUserId)
end)
if success then
stats:GetChildren().Value = Data
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local playerUserId = "Player_"..Player.UserId
local data = game.ReplicatedStorage.PlayerInfo:FindFirstChild(Player.Name.."Data"):GetChildren().Value
local success, errormessage = pcall(function()
DataStore:SetAsync(playerUserId, data)
end)
if success then
print("Successfully saved.")
else
print("Error occured.")
warn(errormessage)
end
end)
I keep getting an error message.