So I have a datastore script that was going well till this happened.
I’m not a expert on this type of stuff, along with that the table I have has like 4000 lines since I wanted to have data for all stuff, I slimmed it down on the bottom post to give a example.
Script in game.Workspace
local DataStore2 = require(game.Workspace.MainModule) -- This is the Module we need I will post it in Description
local Settings = require(game.ReplicatedStorage.ModuleScript) -- You have to use a require(themodulescript/settingsucreated)
game.Players.PlayerAdded:Connect(function(plr) -- Plr added
for i,v in pairs(Settings) do
local datastore = DataStore2(i,plr) --i = the datastorename , plr = the player
local where = v.Where --Where the datastore gets saved at
if v.Where ~= "Player" then
if plr:findFirstChild(v.Where) then--if the folder is already created then
where = plr[v.Where]
else
local folder = Instance.new("Folder",plr) -- creates folder inside player
folder.Name = v.Where -- sets the folder name
where=folder -- this was the mistake
end
end
if v.Where == "Player" then
where= plr
end
--// Creates the Value
local val = Instance.new(v.What,where)
val.Name = i -- // The name u did put on left side inside the Module
val.Value = v.Value --// How much if set
--// Loading
if datastore:Get() ~= nil then -- If datastore already exists
val.Value = datastore:Get() -- loads in plrs data
end
--//Saving
val.Changed:connect(function() -- if Value changes
datastore:Set(val.Value) -- Sets Datastore value to changed Value
end)
end
end)
--It wont save since we are in studio but to make it save in studio we just create a boolvalue inside ServerStorage , make it true
Table
-- To make it public visible on right put "Where" to "leaderstats"
local Settings = {
["ExampleValue"] = {
["Where"] = "leaderstats", -- Player means it gonna save inside player. This will be shown in the main script , this is just our settings, If you put something else it will create a folder inside the plr.
["What"] = "IntValue",
["Value"]= 500,
},
["ExampleValue2"] = {
["Where"] = "leaderstats",
["What"] = "IntValue",
["Value"]= 0,
},
["ExampleValue3"] = {
["Where"] = "leaderstats",
["What"] = "IntValue",
["Value"]= 0,
}
}
return Settings