Hello! I need help finishing my script for SavaData.
Here is my script:
local dss = game:GetService("DataStoreService")
local myDataStore = dss:GetDataStore("myDataStore")
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end)
Here is my leaderstat script
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bigness = Instance.new("IntValue")
bigness.Name = "Bigness"
bigness.Value = 500
bigness.Parent = leaderstats
end)
You could literally just encase all of that inside 1 script for a full on DataStore script
You forgot to end your pcall() function
local dss = game:GetService("DataStoreService")
local myDataStore = dss:GetDataStore("myDataStore")
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end)
local dss = game:GetService("DataStoreService")
local myDataStore = dss:GetDataStore("myDataStore")
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end)
Hm, the SaveData script should be located inside ServerScriptService correct? There might be a rare chance that you may need to use BindToClose() instead
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved when the game was about to shutdown!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end
end)
Bruh you should’ve implemented that yourself though
It’s literally your script
local dss = game:GetService("DataStoreService")
local myDataStore = dss:GetDataStore("myDataStore")
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved when the game was about to shutdown!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end
end)
so should we do this? (We need to definded “player” in game:BindToClose(function()
local dss = game:GetService("DataStoreService")
local myDataStore = dss:GetDataStore("myDataStore")
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-bigness", player.leaderstats.Bigness.Vaule)
end)
if success then
print("Player Data Successfully Saved when the game was about to shutdown!")
else
print("There Was An Erroer When Saving Data")
warn(errormessage)
end
end
end)
end)