So I just created a new game and it is by me and I made this short script
local Datastore = game:GetService("DataStoreService")
local leaderstatsDatastore = Datastore:GetDataStore("leaderstatsDatastore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local money = Instance.new("IntValue", leaderstats)
money.Name = "Money"
money.Value = 0
local playerId = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = leaderstats:GetAsync(playerId)
end)
if success and data then
print("Data Found")
money.Value = data["Money"]
elseif success then
print("No Data Found")
money.Value = 0
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataToSave = {
["Money"] = player.leaderstats.Money.Value
}
local playerId = "Player_"..player.UserId
local success, errormessage = pcall(function()
leaderstatsDatastore:SetAsync(playerId, dataToSave)
end)
if success then
print("Data Saved")
else
warn(errormessage)
end
end)
game:BindToClose(function()
wait(5)
end)
But when I load into the game I get this
GetAsync is not a valid member of Folder
but when I leave the game I get
Data Saved
This happens on line 26 and I don’t know how to fix it. Does anyone have any ideas?