Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't the datastore work? I believe I did everything right. But yet it doesn't save.

Asked by
Ifesol 4
2 years ago
local DataStore = game:GetService("DataStoreService")
local Unlocked5A = DataStore:GetDataStore("Unlocked5001")
local Unlocked15A = DataStore:GetDataStore("Unlocked15001")
local Unlocked25A = DataStore:GetDataStore("Unlocked25001")
local Unlocked35A = DataStore:GetDataStore("Unlocked35001")
local Unlocked45A = DataStore:GetDataStore("Unlocked45001")
local Unlocked55A = DataStore:GetDataStore("Unlocked55001")
local Unlocked65A = DataStore:GetDataStore("Unlocked65001")
local Unlocked75A = DataStore:GetDataStore("Unlocked75001")
local Unlocked85A = DataStore:GetDataStore("Unlocked85001")
local Unlocked95A = DataStore:GetDataStore("Unlocked95001")
local Unlocked100A = DataStore:GetDataStore("Unlocked100001")


game.Players.PlayerAdded:Connect(function(Plr)

    local Levelpasssystem = Instance.new("Folder", Plr)
    Levelpasssystem.Name = "Levelpasssystem"

    local Unlocked5 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked5.Name = "Unlocked5"

    local Unlocked15 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked15.Name = "Unlocked15"
    Unlocked15.Value = false
    local Unlocked25 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked25.Name = "Unlocked25"
    Unlocked25.Value = false
    local Unlocked35 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked35.Name = "Unlocked35"
    Unlocked35.Value = false
    local Unlocked45 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked45.Name = "Unlocked45"
    Unlocked45.Value = false
    local Unlocked55 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked55.Name = "Unlocked55"
    Unlocked55.Value = false
    local Unlocked65 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked65.Name = "Unlocked65"
    Unlocked65.Value = false
    local Unlocked75 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked75.Name = "Unlocked75"
    Unlocked75.Value = false
    local Unlocked85 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked85.Name = "Unlocked85"
    Unlocked85.Value = false
    local Unlocked95 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked95.Name = "Unlocked95"
    Unlocked95.Value = false
    local Unlocked100 = Instance.new("BoolValue", Levelpasssystem)
    Unlocked100.Name = "Unlocked100"
    Unlocked100.Value = false

Unlocked5.Value = Unlocked5A:GetAsync(Plr.UserId) or Unlocked5.Value
Unlocked5A:SetAsync(Plr.UserId, Unlocked5.Value)
Unlocked5.Changed:connect(function()
        Unlocked5A:SetAsync(Plr.UserId, Unlocked5.Value)
    end)
    Unlocked15.Value = Unlocked15A:GetAsync(Plr.UserId) or Unlocked15.Value
    Unlocked15A:SetAsync(Plr.UserId, Unlocked15.Value)
    Unlocked15.Changed:connect(function()
        Unlocked15A:SetAsync(Plr.UserId, Unlocked15.Value)
    end)    
    Unlocked25.Value = Unlocked25A:GetAsync(Plr.UserId) or Unlocked25.Value
    Unlocked25A:SetAsync(Plr.UserId, Unlocked25.Value)
    Unlocked25.Changed:connect(function()
        Unlocked25A:SetAsync(Plr.UserId, Unlocked25.Value)
    end)
    Unlocked35.Value = Unlocked35A:GetAsync(Plr.UserId) or Unlocked35.Value
    Unlocked35A:SetAsync(Plr.UserId, Unlocked35.Value)
    Unlocked35.Changed:connect(function()
        Unlocked35A:SetAsync(Plr.UserId, Unlocked35.Value)
    end)
    Unlocked45.Value = Unlocked5A:GetAsync(Plr.UserId) or Unlocked45.Value
    Unlocked45A:SetAsync(Plr.UserId, Unlocked45.Value)
    Unlocked45.Changed:connect(function()
        Unlocked45A:SetAsync(Plr.UserId, Unlocked45.Value)
    end)
    Unlocked55.Value = Unlocked55A:GetAsync(Plr.UserId) or Unlocked55.Value
    Unlocked55A:SetAsync(Plr.UserId, Unlocked55.Value)
    Unlocked55.Changed:connect(function()
        Unlocked55A:SetAsync(Plr.UserId, Unlocked55.Value)
    end)
    Unlocked65.Value = Unlocked65A:GetAsync(Plr.UserId) or Unlocked65.Value
    Unlocked65A:SetAsync(Plr.UserId, Unlocked65.Value)
    Unlocked65.Changed:connect(function()
        Unlocked65A:SetAsync(Plr.UserId, Unlocked65.Value)
    end)
    Unlocked75.Value = Unlocked75A:GetAsync(Plr.UserId) or Unlocked75.Value
    Unlocked75A:SetAsync(Plr.UserId, Unlocked75.Value)
    Unlocked75.Changed:connect(function()
        Unlocked75A:SetAsync(Plr.UserId, Unlocked75.Value)
    end)
    Unlocked85.Value = Unlocked85A:GetAsync(Plr.UserId) or Unlocked85.Value
    Unlocked85A:SetAsync(Plr.UserId, Unlocked85.Value)
    Unlocked85.Changed:connect(function()
        Unlocked85A:SetAsync(Plr.UserId, Unlocked85.Value)
    end)
    Unlocked95.Value = Unlocked95A:GetAsync(Plr.UserId) or Unlocked95.Value
    Unlocked95A:SetAsync(Plr.UserId, Unlocked95.Value)
    Unlocked95.Changed:connect(function()
        Unlocked95A:SetAsync(Plr.UserId, Unlocked95.Value)
    end)
    Unlocked100.Value = Unlocked100A:GetAsync(Plr.UserId) or Unlocked100.Value
    Unlocked100A:SetAsync(Plr.UserId, Unlocked100.Value)
    Unlocked100.Changed:connect(function()
        Unlocked100A:SetAsync(Plr.UserId, Unlocked100.Value)
    end)
end)

game.Players.PlayerRemoving:connect(function(Player)
    Unlocked5A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked5.Value)
    Unlocked15A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked15.Value)
    Unlocked25A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked25.Value)
    Unlocked35A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked35.Value)
    Unlocked45A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked45.Value)
    Unlocked55A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked55.Value)
    Unlocked65A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked65.Value)
    Unlocked75A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked75.Value)
    Unlocked85A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked85.Value)
    Unlocked95A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked95.Value)
    Unlocked100A:SetAsync(Player.UserId, Player.Levelpasssystem.Unlocked100.Value)
end)
0
Hey there, I believe this could be an error due to the high usage of GetAsync() and SetAsync(). Could you tell me if there are any errors/warns in the output? Neatwyy 123 — 2y
0
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1567905486 (x2) Ifesol 4 — 2y
0
This is NOT how you use datastores... Soban06 410 — 2y
0
Of course you were going to get the "DataStore request was added to queue". You only create 1 datastore and save all your values in it. You don't create a new data store for each value. Soban06 410 — 2y
0
So what should I do Ifesol 4 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

this is a glitch with roblox. i have been making datastores for commissions and all the people want a refund so i suggest using a different type of datastore like what i made under this -- // Assigning variables // local DataStoreService = game:GetService("DataStoreService") local dataStore = DataStoreService:GetDataStore("MyDataStore") -- This can be changed to whatever you want

local function saveData(player) -- The functions that saves data

local tableToSave = {
    player.leaderstats.Money.Value; -- First value from the table
    player.leaderstats.Coins.Value -- Second value from the table
}

local success, err = pcall(function()
    dataStore:SetAsync(player.UserId, tableToSave) -- Save the data with the player UserId, and the table we wanna save
end)

if success then -- If the data has been saved
    print("Data has been saved!")
else -- Else if the save failed
    print("Data hasn't been saved!")
    warn(err)       
end

end

game.Players.PlayerAdded:Connect(function(player) -- When a player joins the game

-- // Assigning player stats // local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats

local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats

local data -- We will define the data here so we can use it later, this data is the table we saved
local success, err = pcall(function()

    data = dataStore:GetAsync(player.UserId) -- Get the data from the datastore

end)

if success then -- If there were no errors and player loaded the data

    Money.Value = data[1] -- Set the money to the first value of the table (data)
    Coins.Value = data[2] -- Set the coins to the second value of the table (data)

else -- The player didn't load in the data, and probably is a new player
    print("The player has no data!") -- The default will be set to 0
end

end)

game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves local success, err = pcall(function() saveData(player) -- Save the data end)

if success then
    print("Data has been saved")
else
    print("Data has not been saved!")
end

end)

game:BindToClose(function() -- When the server shuts down for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players local success, err = pcall(function() saveData(player) -- Save the data end)

    if success then
        print("Data has been saved")
    else
        print("Data has not been saved!")
    end
end

end)

0
you need to copy all that it made it into different parts idk why dradcdffefgd 0 — 2y
0
It's not working, Can u help me in team create or something Ifesol 4 — 2y
Ad

Answer this question