Hello! Everyone I has a problem I'm trying to save table but I'm getting
22:29:18.232 - HTTP 0 (HTTP 403 (HTTP/1.1 403 Forbidden))
22:29:18.232 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests. Key =
22:29:19.366 - Data store TestyData_RT5R1 was not saved as it was not updated.
How to fix that?
Script:
local DataStoreModule = require(1936396537) local Empty = { Coins = 0, Wins = 0 } game.Players.PlayerAdded:Connect(function(Player) local newFolder = Instance.new("Folder",Player) newFolder.Name = "leaderstats" local CoinsValue = Instance.new("IntValue",newFolder) RepValue.Name = "Coins" local WinsValue = Instance.new("IntValue",newFolder) WinsValue.Name = "Wins" local DataStore = DataStoreModule("TestyData_RT5R1",Player) local reqAsync = DataStore:GetTable(Empty) if reqAsync then CoinsValue.Value = reqAsync.Coins WinsValue.Value = reqAsync.Wins end end)
Just as angel1001 said.. its quite simple. And you dont necessarily need a module for this. So lets get this correct and explained. :)
So first off id like you to open this link before you go any further: https://www.robloxdev.com/api-reference/class/DataStoreService
Links to rest of functions used here (you dont have to open them unless you dont understand the code below) Storage: https://www.robloxdev.com/api-reference/function/DataStoreService/GetDataStore GetAsync: https://www.robloxdev.com/api-reference/function/GlobalDataStore/GetAsync SetAsync: https://www.robloxdev.com/api-reference/function/GlobalDataStore/SetAsync
Also please remember datastore is SERVER side only!
So here is how easy datastore is to set up (also because you are using a module this will also be a module)
Module named "DataStoreModule" under our parent script
local module = {} local DS = game:GetService("DataStoreService") -- Grabs the service we need local Storage = DS:GetDataStore("Test01") -- Our storage function module:GetPlayerData(Player) local Data = Storage:GetAsync(Player.UserId) if Data == nil then Data = {Wins =0, Coins =0} -- a new user end return Data end function module:SavePlayerData(Player, Data) Storage:SetAsync(Player.UserId, Data) return true end return module
Our script
local DS = require("DataStoreModule") local Players = game.Players Players.PlayerAdded:connect(function(p) local newFolder = Instance.new("Folder",Player) newFolder.Name = "leaderstats" local CoinsValue = Instance.new("IntValue",newFolder) RepValue.Name = "Coins" local WinsValue = Instance.new("IntValue",newFolder) WinsValue.Name = "Wins" local Data = DS:GetPlayerData(p) wait() CoinsValue.Value = Data.Coins WinsValue.Value = Data.Wins end) --[[ And finally to save a players data its simple as this DS:SavePlayerData(Player, {Coins = CoinsValue.Value, Wins = WinsValue.Value}) (try to save right before they leave the game using Players.PlayerLeaving) ]]--
Hello! With Datastore2, there is actually a really simple way to save data with tables. Just look at this script:
local Players = game:GetService("Players") local ServerStorage = game:GetService("ServerStorage") local ServerScriptService = game:GetService("ServerScriptService") local DataStore2 = require(ServerScriptService:WaitForChild("DataStore2")) DataStore2.Combine("DATA-Test","MainDataStore-Test") local defaultTab = { AverageTypingSpeed = 0; PersonalBestTypingSpeed = 0; PersonalBestScore = 0 } Players.PlayerAdded:Connect(function(player) local MainDataStore = DataStore2("MainDataStore-Test",player) local Folder = Instance.new("Folder"); Folder.Name = "Values"; Folder.Parent = player local ATS = Instance.new("IntValue"); ATS.Name = "AverageTypingSpeed"; ATS.Value = 0; local PBTS = Instance.new("IntValue"); PBTS.Name = "PersonalBestTypingSpeed"; PBTS.Value = 0; local TypingSpeed = Instance.new("IntValue"); TypingSpeed.Name = "TypingSpeed"; TypingSpeed.Value = 0; local Score = Instance.new("IntValue"); Score.Name = "Score"; Score.Value = 0; local PBScore = Instance.new("IntValue"); PBScore.Name = "PersonalBestScore"; PBScore.Value = 0; local function updateDataStore(updatedValue) MainDataStore:SetBackup(5) -- Retry 5 times, give up after print("IsBackup:", MainDataStore:IsBackup()) -- Is it using a backup? local tab = MainDataStore:Get(updatedValue) ATS.Value = tab["AverageTypingSpeed"] PBTS.Value = tab["PersonalBestTypingSpeed"] PBScore.Value = tab["PersonalBestScore"] end updateDataStore(defaultTab) MainDataStore:OnUpdate(updateDataStore) ATS.Parent = Folder PBTS.Parent = Folder TypingSpeed.Parent = Folder Score.Parent = Folder PBScore.Parent = Folder end)
What's happening here? Well when the function "updateDataStore" is ran, it will first tell DataStore2 that it can try to get the table 5 times before it "pretends" there is no table. (See Here) If they successfully retrieve the table, you can then assign each value that you wanted to be saved to a value in the table.
Example.Value = exampleTab["Example"]
Now, to update/save the table, you can't actually use the increment function for this. You will have to use the Set function instead. I believe this is the only way you can save tables? At least to my knowledge. If you do find another function that could save tables then lmk :)
local newTable = { AverageTypingSpeed = 15; -- change to something new PersonalBestTypingSpeed = 5; -- change to something new PersonalBestScore = 12 -- change to something new } MainDataStore:Set(newTable)
This should work and hopefully you can use this for whatever project your working on :) Have a great day!
:SetAsync(userid, table)
Simple as that.
Hope this helped.