A friend of mine made this, and im worried about its ability to reliably save and get data. Ive had issues with it and im scared to launch the game with this broken datastore. is there anyway i can make it more reliable? (Idk how to use datastore 2)
local RS = game:GetService("ReplicatedStorage")
local SendsAndGets = RS:WaitForChild("SetVals")
local DSS = game:GetService("DataStoreService")
local SaveToDS = DSS:GetDataStore("InvisLeaderstatsDS1")
local ValsToSaveAndRetrieve = {"OverheadName", "PlayerFindable", "NotifLocal"}
local function GetData(player)
local invisleaderstats = Instance.new("Folder")
invisleaderstats.Name = "invisleaderstats"
invisleaderstats.Parent = player
local OverheadName = Instance.new("StringValue")
OverheadName.Name = "OverheadName"
OverheadName.Value = ""
OverheadName.Parent = invisleaderstats
local PlayerFindable = Instance.new("BoolValue")
PlayerFindable.Name = "PlayerFindable"
PlayerFindable.Value = false
PlayerFindable.Parent = invisleaderstats
local notif = Instance.new("StringValue")
notif.Name = "NotifLocal"
notif.Value = "BR"
notif.Parent = invisleaderstats
local data = nil
local success, errormessage = pcall(function()
data = SaveToDS:GetAsync(player.UserId.." | ILSdataVAL")
if data ~= nil then
print(data)
else
print("No data there welp!")
end
end)
if success then
for i = 1, #ValsToSaveAndRetrieve do
if typeof(data) == 'table' then
if data[ValsToSaveAndRetrieve[i]] ~= nil then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = data[ValsToSaveAndRetrieve[i]]
print("ILS - "..player.Name.." ("..player.DisplayName..", "..player.UserId.."): The data of "..ValsToSaveAndRetrieve[i].." was retrieved!")
else
warn("ILS - "..player.Name.." ("..player.DisplayName..", "..player.UserId.."): The data of "..ValsToSaveAndRetrieve[i].." was not retrieved!")
if player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("IntValue") then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = 0
elseif player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("StringValue") then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = ""
elseif player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("BoolValue") then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = false
end
end
else
warn("ILS - "..player.Name.." ("..player.DisplayName..", "..player.UserId.."): The data of "..ValsToSaveAndRetrieve[i].." was not retrieved!")
if player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("IntValue") then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = 0
elseif player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("StringValue") then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = ""
elseif player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("BoolValue") then
player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]).Value = false
end
end
end
else
print("ILS - "..player.Name.." ("..player.DisplayName..", "..player.UserId.."): The data was not retrieved!")
warn("ILS - "..errormessage)
player:Kick("ILS - Player data failed to load or is corrupted. Please rejoin!")
end
for i = 1, #ValsToSaveAndRetrieve do
if player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("IntValue") then
local Newval = Instance.new("IntValue")
Newval.Parent = RS
Newval.Name = ValsToSaveAndRetrieve[i].."val | "..player.UserId
elseif player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("StringValue") then
local Newval = Instance.new("StringValue")
Newval.Parent = RS
Newval.Name = ValsToSaveAndRetrieve[i].."val | "..player.UserId
elseif player:WaitForChild("invisleaderstats"):WaitForChild(ValsToSaveAndRetrieve[i]):IsA("BoolValue") then
local Newval = Instance.new("BoolValue")
Newval.Parent = RS
Newval.Name = ValsToSaveAndRetrieve[i].."val | "..player.UserId
end
end
end
local function SaveData(player)
local SavedData = {}
for i = 1, #ValsToSaveAndRetrieve do
SavedData[ValsToSaveAndRetrieve[i]] = RS:WaitForChild(ValsToSaveAndRetrieve[i].."val | "..player.UserId).Value
print(ValsToSaveAndRetrieve[i].. " = ".. tostring(RS:WaitForChild(ValsToSaveAndRetrieve[i].."val | "..player.UserId).Value))
end
print(SavedData)
local success, errormessage = pcall(function()
SaveToDS:SetAsync(player.UserId.." | ILSdataVAL", SavedData)
end)
if success then
local RSChildren = RS:GetChildren()
print("ILS - "..player.Name.." ("..player.DisplayName..", "..player.UserId..") has saved their data!")
for i = 1, #RSChildren do
if string.find(RSChildren[i].Name, player.UserId) then
RSChildren[i]:Destroy()
print("killed "..RSChildren[i].Name)
end
end
else
print("ILS - There was nothing saved!")
warn(errormessage)
end
end
game:GetService("Players").PlayerAdded:Connect(GetData)
game:GetService("Players").PlayerRemoving:Connect(SaveData)
game:BindToClose(function()
for _, v in pairs(game:GetService("Players"):GetPlayers()) do
SaveData(v)
end
end)
local event = game.ReplicatedStorage.Geodude
event.OnServerEvent:Connect(function(plr)
GetData(plr)
end)
Thank you if you can help me learn to fix this, i dont know how to use datastore, and i dont want to make the creator sad by basically saying “Your datastore is bad, fix it”