So, lately i’ve added data saving in a game im developing with my friends. The datastore saves your current loadout and what you have bought. The second part works fine, however, sometimes it doesnt save your loadout.
I’m adding here the parts with the script that sets up datastores
Datastore2 Set up
–T = Loadout (Not working properly), AT = What you’ve bought (Works properly)
–Note = i’m setting slots to “nil” to make it a string (for some reason it didnt work as nil)
local function setupUserData()
local userData = {
AT = {
Sniper = false,
Soldier = false,
MG = false,
Bank = false,
SMG = false,
Demolitionist = false
};
T = {
T1 = "nil",
T2 = "nil",
T3 = "nil",
T4 = "nil",
T5 = "nil"
};
}
return userData
end
local userData = Datastore2(userDataStoreName, plr):GetTable(setupUserData())
Equip function
function Equip()
local T1V = script.Parent.Parent.Parent.Parent.Parent.Slots.T1.T
local T2V = script.Parent.Parent.Parent.Parent.Parent.Slots.T2.T
local T3V = script.Parent.Parent.Parent.Parent.Parent.Slots.T3.T
local T4V = script.Parent.Parent.Parent.Parent.Parent.Slots.T4.T
local T5V = script.Parent.Parent.Parent.Parent.Parent.Slots.T5.T
if T1V.Value == nil or T1V.Value == "nil" then
userData["T"]["T1"] = Title.Text
T1V.Value = Title.Text
script.Parent.Parent.Parent.Parent.Parent.Slots.T1.Image = script.Parent.Parent.Parent.Parent.Parent.ScrollingFrame.Towers[Title.Text].Image
Datastore2(userDataStoreName, plr):Set(userData)
elseif T2V.Value == nil or T2V.Value == "nil" and T1V.Value ~= nil and T1V.Value ~= Title.Text and T2V.Value ~= Title.Text and T3V.Value ~= Title.Text and T4V.Value ~= Title.Text and T5V.Value ~= Title.Text then
userData["T"]["T2"] = Title.Text
T2V.Value = Title.Text
Datastore2(userDataStoreName, plr):Set(userData)
script.Parent.Parent.Parent.Parent.Parent.Slots.T2.Image = script.Parent.Parent.Parent.Parent.Parent.ScrollingFrame.Towers[Title.Text].Image
elseif T3V.Value == nil or T3V.Value == "nil" and T2V.Value ~= nil and T1V.Value ~= nil and T1V.Value ~= Title.Text and T2V.Value ~= Title.Text and T3V.Value ~= Title.Text and T4V.Value ~= Title.Text and T5V.Value ~= Title.Text then
userData["T"]["T3"] = Title.Text
T3V.Value = Title.Text
Datastore2(userDataStoreName, plr):Set(userData)
script.Parent.Parent.Parent.Parent.Parent.Slots.T3.Image = script.Parent.Parent.Parent.Parent.Parent.ScrollingFrame.Towers[Title.Text].Image
elseif T4V.Value == nil or T4V.Value == "nil" and T3V.Value ~= nil and T2V.Value ~= nil and T1V.Value ~= nil and T1V.Value ~= Title.Text and T2V.Value ~= Title.Text and T3V.Value ~= Title.Text and T4V.Value ~= Title.Text and T5V.Value ~= Title.Text then
userData["T"]["T4"] = Title.Text
T4V.Value = Title.Text
Datastore2(userDataStoreName, plr):Set(userData)
script.Parent.Parent.Parent.Parent.Parent.Slots.T4.Image = script.Parent.Parent.Parent.Parent.Parent.ScrollingFrame.Towers[Title.Text].Image
elseif T5V.Value == nil or T5V.Value == "nil" and T4V.Value ~= nil and T3V.Value ~= nil and T2V.Value ~= nil and T1V.Value ~= nil and T1V.Value ~= Title.Text and T2V.Value ~= Title.Text and T3V.Value ~= Title.Text and T4V.Value ~= Title.Text and T5V.Value ~= Title.Text then
userData["T"]["T5"] = Title.Text
T5V.Value = Title.Text
Datastore2(userDataStoreName, plr):Set(userData)
script.Parent.Parent.Parent.Parent.Parent.Slots.T5.Image = script.Parent.Parent.Parent.Parent.Parent.ScrollingFrame.Towers[Title.Text].Image
end
Datastore2(userDataStoreName, plr):Save()
debounce = false
end
I also wanted to specify that this error occurs sometimes, not every time a player joins the game.