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

My Data Stores aren't allowing me to receive my data can anyone help me?

Asked by 4 years ago

No errors are showing in the Output section. Please help me. Here is the method I tried to use ~~~~~~~~~~~~~~~~~ local DataStoreService = game:GetService("DataStoreService")

local MyDataStore1 = DataStoreService:GetDataStore("MyDataStore1")
local MyDataStore2 = DataStoreService:GetDataStore("MyDataStore2")
local MyDataStore3 = DataStoreService:GetDataStore("MyDataStore3")
local MyDataStore4 = DataStoreService:GetDataStore("MyDataStore4")
local MyDataStore5 = DataStoreService:GetDataStore("MyDataStore5")
local MyDataStore6 = DataStoreService:GetDataStore("MyDataStore6")
local MyDataStore7 = DataStoreService:GetDataStore("MyDataStore7")
local MyDataStore8 = DataStoreService:GetDataStore("MyDataStore8")
local MyDataStore9 = DataStoreService:GetDataStore("MyDataStore9")

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

    local Stats = Instance.new("IntValue",player)
    Stats.Name = "Stats"
    Stats.Value = nil

    local Level = Instance.new("IntValue",Stats)
    Level.Name = "Lv"
    Level.Value = 1

    local Exp = Instance.new("IntValue",Stats)
    Exp.Name = "Current"
    Exp.Value = 0

    local MaxExp = Instance.new("IntValue",Stats)
    MaxExp.Name = "Max"
    MaxExp.Value = 100

    local Points = Instance.new("IntValue",Stats)
    Points.Name = "Points"
    Points.Value = 0

    local MPoints = Instance.new("IntValue",Stats)
    MPoints.Name = "MPoints"
    MPoints.Value = 1

    local SPoints = Instance.new("IntValue",Stats)
    SPoints.Name = "SPoints"
    SPoints.Value = 1

    local GPoints = Instance.new("IntValue",Stats)
    GPoints.Name = "GPoints"
    GPoints.Value = 1

    local DPoints = Instance.new("IntValue",Stats)
    DPoints.Name = "DPoints"
    DPoints.Value = 1

    local FPoints = Instance.new("IntValue",Stats)
    FPoints.Name = "FPoints"
    FPoints.Value = 1

    local data1
    local data2
    local data3
    local data4
    local data5
    local data6
    local data7
    local data8
    local data9

    local success, errormessage = pcall(function()
        data1 = MyDataStore1:GetAsync(player.UserId.."Level")
        data2 = MyDataStore2:GetAsync(player.UserId.."Exp")
        data3 = MyDataStore3:GetAsync(player.UserId.."MExp")
        data4 = MyDataStore3:GetAsync(player.UserId.."Points")
        data5 = MyDataStore1:GetAsync(player.UserId.."MP")
        data6 = MyDataStore2:GetAsync(player.UserId.."SP")
        data7 = MyDataStore3:GetAsync(player.UserId.."GP")
        data8 = MyDataStore3:GetAsync(player.UserId.."DP")
        data9 = MyDataStore3:GetAsync(player.UserId.."FP")
    end)

    if success then
        Level.Value = data1
        Exp.Value = data2
        MaxExp.Value = data3    
        Points.Value = data4
        MPoints.Value = data5
        SPoints.Value = data6
        GPoints.Value = data7
        DPoints.Value = data8
        FPoints.Value = data9
    else
        print("There was an error while receiving data")
        warn(errormessage)
    end

end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall(function()
        MyDataStore1:SetAsync(player.UserId.."Level",player.Stats.Lv.Value)                              
            MyDataStore2:SetAsync(player.UserId.."Exp",player.Stats.Current.Value)
        MyDataStore3:SetAsync(player.UserId.."MExp",player.Stats.Max.Value)
        MyDataStore4:SetAsync(player.UserId.."Points",player.Stats.Points.Value)
        MyDataStore5:SetAsync(player.UserId.."MP",player.Stats.MPoints.Value)
        MyDataStore6:SetAsync(player.UserId.."SP",player.Stats.SPoints.Value)
        MyDataStore7:SetAsync(player.UserId.."GP",player.Stats.GPoints.Value)
        MyDataStore8:SetAsync(player.UserId.."DP",player.Stats.DPoints.Value)
        MyDataStore9:SetAsync(player.UserId.."FP",player.Stats.FPoints.Value)
    end)

    if success then
        print("Data Saved Successfully!")
    else
        print("There was an error while saving data")
        warn(errormessage)
    end
end)

~~~~~~~~~~~~~~~~~

0
First of all, you shouldn't be using several DataStores that only hold 1 key/value pair each. You only need 1 DataStore that saves several key/value pairs (Level, Exp, MExp, etc...) Roger111 347 — 4y
0
That's like amazon making a warehouse for every single product they make, instead of holding as many products as they can in one warehouse. Roger111 347 — 4y
0
And you said there are "No errors" in your output. But does it print anything? If not then write some print statements in your code so we can prove that it is running in specific places. Roger111 347 — 4y
1
How do I save multiple data in 1 DataStore? AuraBeast1 8 — 4y
View all comments (5 more)
0
Instead of doing SetAsync() with every DataStore, instead do several SetAsync()'s to one datastore. (just change all of them to DataStore1 and remove the extras that you declared at the top.) Roger111 347 — 4y
0
I dont understand AuraBeast1 8 — 4y
0
Then you need to refer to the wiki, or hope that someone has the time of day to revise all of your code by themselves. https://developer.roblox.com/en-us/articles/Data-store Roger111 347 — 4y
0
There is more immediate help on the discord server. https://discord.com/invite/UDpAX35 Roger111 347 — 4y
0
use datastore 2 lol its more efficient MmadProgrammer 35 — 4y

Answer this question