So I have been working on this Datatore and when I finished it did not save my data and i was wondering if anyone knows why.
here’s the script:
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue", leaderstats)
Points.Name = "Points"
Points.Value = 0
local playerUserId = "Player_"..player.UserId
-- load data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Points.Value = data
-- set our data to points
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId
local data = player.leaderstats.Points.Value
local success, errormessage = pcall(function()
myDataStore:setAsync(playerUserId, data)
end)
if success then
print("Data saved")
else
print("There was a error")
warn(errormessage)
end
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue", leaderstats)
Points.Name = "Points"
Points.Value = 0
local playerUserId = "Player_"..player.UserId
-- load data
local success, errormessage = pcall(function()
return myDataStore:GetAsync(playerUserId)
end)
if success then
Points.Value = errormessage -- ignore the name man
-- set our data to points
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId
local data = player.leaderstats.Points.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data saved")
else
print("There was a error")
warn(errormessage)
end
end)