In the game that I had been making, I plan for players to be able to save their progress to continue form session to session. This can be easily achieved by using DataStore. Te problem is, I don't know how to use datastore that well. I made a script to save the values that I had wanted, but when I tested it out and updated the values, I had reviewed a message that the request had been throttled and that I should send fewer requests. Is there a way that I could save all five of these values(With plans to add two more on a later date) under one datastore? Here is the script that I had used
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("ExampleDataStore")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "OnionStore"
local red = Instance.new("IntValue",leader)
red.Name = "Red"
local yellow = Instance.new("IntValue",leader)
yellow.Name = "Yellow"
local blue = Instance.new("IntValue",leader)
blue.Name = "Blue"
local purple = Instance.new("IntValue",leader)
purple.Name = "Purple"
local white = Instance.new("IntValue",leader)
white.Name = "White"
red.Value = ds1:GetAsync(player.UserId) or 1
ds1:SetAsync(player.UserId,red.Value)
red.Changed:connect(function()
print('Saving Data')
ds1:SetAsync(player.UserId,red.Value)
print(player.Name.."'s Data of"..red.Value.." "..red.Name.."has been saved!")
end)
yellow.Value = ds1:GetAsync(player.UserId) or 1
ds1:SetAsync(player.UserId,yellow.Value)
yellow.Changed:connect(function()
print('Saving Data')
ds1:SetAsync(player.UserId,yellow.Value)
print(player.Name.."'s Data of"..yellow.Value.." "..yellow.Name.."has been saved!")
end)
blue.Value = ds1:GetAsync(player.UserId) or 1
ds1:SetAsync(player.UserId,blue.Value)
blue.Changed:connect(function()
print('Saving Data')
ds1:SetAsync(player.UserId,blue.Value)
print(player.Name.."'s Data of"..blue.Value.." "..blue.Name.."has been saved!")
end)
purple.Value = ds1:GetAsync(player.UserId) or 0
ds1:SetAsync(player.UserId,purple.Value)
purple.Changed:connect(function()
print('Saving Data')
ds1:SetAsync(player.UserId,purple.Value)
print(player.Name.."'s Data of"..purple.Value.." "..purple.Name.."has been saved!")
end)
white.Value = ds1:GetAsync(player.UserId) or 0
ds1:SetAsync(player.UserId,white.Value)
white.Changed:connect(function()
print('Saving Data')
ds1:SetAsync(player.UserId,white.Value)
print(player.Name.."'s Data of"..white.Value.." "..white.Name.."has been saved!")
end)
end)

3 comments
Yes: Get once and save to a variable. But since you save each value to the same key, I don't think you are saving anything but White
It's better to put [Solved], as this will actually mark the question as answered with that green check mark and stuff
make that blue