Hey everyone, with my current Datastore it works but it appears everything I leave the game I keep getting that datastore saving queue issues, and with me adding new things into the game I keep adding new data for bools or number values etc so I'm just wondering if there is a better way how I can code this. (I know it may look like really bad coding but it does the job)
#How can I Improve my datastore here?
45 messages · Page 1 of 1 (latest)
so what does that do for the Game
Basically everything in here holds all the stats and data for the player
For example when they leave it saves their clicks value and when they join it gives it back to them
local Player = game.Players
Player.PlayerAdded:Connect(function(player)
local Folders = {
{key = 'leaderstats'},{key = 'MainFolder'},{key = 'Stats'},{key = 'CostFolder'}
}
for i,v in ipairs(Folders) do -- add "in ipairs(Folders)" here
local Folder = Instance.new('Folder', player)
Folder.Name = v.key
print(Folder.Name)
end
end)```
why
but this is what it should look like for the Folder Adding
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
This also works it's just another way of doing it
You can store all the values in one DataStore as a table
na that way is kinda not good
leaderstats.Parent = plr
its better to dolua local ls = Instance.new('Folder',player)
Its good both ways
Both ways work the same
The only difference is that one has one more line
Also, why you need the data store?
I'm you can make it in under 50 lines
ye dont listen to AVG since doing a table to handle the instances of the Folders Name
Wtf do you mean?
Would a table help the issue of the datastore saving queue when someone leaves / joins?
also i read that u cant have more than 2 SetAsync
That might be why I'm getting the queuing error then
I dont think you get what I mean:
You create a empty table, loop thru every stat you want to save and add the stat.Name and stat.Value inside the table you have created. After the loop is done, just save the table
When a player joins, check if he was data and if it does, loop thru stats and load data from the table to .Value using the .Name to get the specific data
so its better to dolua function UpdateData(player) local Update = {} local ls = player:FindFirstChild('leaderstats'):GetChildren() local MainFolder = player:FindFirstChild('MainFolder'):GetChildren() local CostFolder = player:FindFirstChild('CostFolder'):GetChildren() for i,v in pairs(ls) do Update[v.Name] = v.Value end for i,v in pairs(MainFolder) do Update[v.Name] = v.Value end for i,v in pairs(CostFolder) do Update[v.Name] = v.Value end return Update end game.Players.PlayerRemoving:Connect(function(player) local ToUpdateData = UpdateData(player) DataStore:SetAsync(player.UserId,ToUpdateData) end)
Yes, requesting a lot of DataStores very fast will add you in a queue because Roblox servers will limit your request time
Exactly, this is want I was trying to say
I'll set that up and change it all
Thanks both of you
for i,v in pairs(ls:GetChildren()) do
if ToSave then
v.Value = ToSave[v.Name]
end
end```
I would recommend you to create a folder where you have every stat you need (Call it DataFolder or smth like that) and don't have anything inside a leaderstats folder that need to be saved
far better thanlua if ToSave then Cost.Value = ToSave.Cost Points.Value = ToSave.Points Money.Value = ToSave.Money end
Here is an example of how you can do it (you could improve it in many ways, but this is just perfect for someone who just start scripting)
oh kinda looks to long and hard to read