Hello, so today I tried to make a data saving script which I’m super bad at understanding things in the script. (I barely learn any scripting and I only know the basics)
-
What do you want to achieve? Ways to fix my data saving script.
-
What is the issue?
-
What solutions have you tried so far? I have tried looking for solutions but I don’t find anything useful and doubt anybody even have the same problem as mine in the first place. I don’t even understand my own script.
Script:
local DSS = game:GetService("DataStoreService")
local mDS = DSS:GetDataStore("mDS")
game.Players.PlayerAdded:Connect(function(player)
local PLRData = Instance.new("Folder", player)
PLRData.Name = "PlayerData"
local currentSpirit = Instance.new("StringValue", PLRData)
currentSpirit.Name = "Spirit"
local data
local success, errormessage = pcall(function()
data = mDS:GetAsync(player.UserId.."-spirit")
end)
if success then
currentSpirit.Value = data
else
print("Error getting data. Please check errormessage")
warn(errormessage) --This line broke
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
mDS:SetAsync(player.UserId.."-spirit",player.PlayerData.SpiritName.Value)
end)
if success then
print("Data saved")
else
print("Failed! Please check errormessage")
warn(errormessage)
end
end)
Note that I’m trying to understand and getting the hang of scripting and this is my first step, every helping hands possible is appreciated. Thank you!
Problem is solved but no replies are suitable for the solution mark.