So I am trying to make a datastore for my leaderstat Money
. It says Setasync is not a valid member of the datastoreservice
. So I tried looking at it in the documentation page but it just is using Setasync
local datastore = game:GetService("DataStoreService")
local DataStore1 = datastore:GetDataStore("PlayerMoney")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name= "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = leaderstats
local playerID = "Player_"..player.UserId
print(playerID)
local data
local success, errormessage = pcall(function()
data = DataStore1:GetAsync(playerID)
end)
if success then
money.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerID = "Player_"..player.UserId
local data = player.leaderstats.Money.Value
local success, errormessage = pcall(function()
datastore:SetAsync(playerID, data)
end)
if success then
print("data saved")
else
print("Data failed to save")
warn(errormessage)
end
end)
Thanks!