I was following a tutorial from AlvinBlox, because I'm relatively new to RBX Lua scripting, on how to DataStore leaderstats. I couldn't really find anything on Youtube that stored multiple leaderstats and worked for me, so I tried to common-sense my way out of the problem. Turns out this doesn't work, because even though everything prints out success it doesn't actually load anything in. If anyone could fix up my code and/or tell me why it doesn't work would be greatly appreciated.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local myDataStore2 = DataStoreService:GetDataStore("myDataStore2")
local myDataStore3 = DataStoreService:GetDataStore("myDataStore3")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Points = Instance.new("IntValue")
Points.Name = "LagPoints"
Points.Parent = leaderstats
local Minutes = Instance.new("IntValue")
Minutes.Name = "Minutes"
Minutes.Parent = leaderstats
local Bricks = Instance.new("IntValue")
Bricks.Name = "Bricks"
Bricks.Parent = leaderstats
local datapoints
local dataminutes
local databricks
local success, errormessage = pcall(function()
datapoints = myDataStore:GetAsync(player.UserId.."-points")
end)
if success then
Points.Value = datapoints
print("Data succesfully loaded your LagPoints.")
else
print("There was an error whilst getting your data for LagPoints.")
end
local success, errormessage = pcall(function()
dataminutes = myDataStore2:GetAsync(player.UserId.."-mins")
end)
if success then
Points.Value = dataminutes
print("Data succesfully loaded your Minutes in Lag-Mode.")
else
print("There was an error whilst getting your data for Minutes.")
end
local success, errormessage = pcall(function()
datapoints = myDataStore3:GetAsync(player.UserId.."-bricks")
end)
if success then
Points.Value = databricks
print("Data succesfully loaded your Bricks Spawned.")
else
print("There was an error whilst getting your data for Bricks.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-points",player.leaderstats.LagPoints.Value)
end)
if success then
print(player.Name.."'s Data Saved Succesfully.")
else
print("There was an error saving "..player.Name.."'s data!")
warn(errormessage)
end
local success, errormessage = pcall(function()
myDataStore2:SetAsync(player.UserId.."-mins",player.leaderstats.Minutes.Value)
end)
if success then
print(player.Name.."'s Data Saved Succesfully.")
else
print("There was an error saving "..player.Name.."'s data!")
warn(errormessage)
end
local success, errormessage = pcall(function()
myDataStore3:SetAsync(player.UserId.."-bricks",player.leaderstats.Bricks.Value)
end)
if success then
print(player.Name.."'s Data Saved Succesfully.")
else
print("There was an error saving "..player.Name.."'s data!")
warn(errormessage)
end
end)
