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

CAN SOME ONE HELP ME WITH DATA SAVING AND LOADING?

Asked by 5 years ago

Hi, Can some one please help me? i try to save and load my data in the playerdatastore. but i dont know what is wrong with it, and as i see nothing is wrong at all. i dont get errors but also my data wont save and or load. i looked up a tutorial and did every thing they say in it, put api on on site and every thing, but still not working.

Please help!

so i have this code:

local currencyNameA = "Coins"
local currencyNameB = "Gold"

local DataStore = game:GetService("DataStoreService"):GetDataStore("PlrDataStore")

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

    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player

    local currencyA = Instance.new("IntValue")
    currencyA.Name = currencyNameA
    currencyA.Parent = folder

    local currencyB = Instance.new("IntValue")
    currencyB.Name = currencyNameB
    currencyB.Parent = folder

    local aID = currencyNameA.."_"..player.UserId
    local bID = currencyNameB.."_"..player.UserId
    local asavedData = nil
    local bsavedData = nil

    pcall(function()
        asavedData = DataStore:GetAsync(aID)
        bsavedData = DataStore:GetAsync(bID)
    end)

    if asavedData ~= nil and bsavedData ~= nil then
        currencyA.Value = asavedData
        currencyB.Value = bsavedData
        print("Data loaded")
    else
        -- New Player
        currencyA.Value = 0
        currencyB.Value = 0
        print("New Player to the game")
    end

end)

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

    local aID = currencyNameA.."_"..player.UserId
    local bID = currencyNameB.."_"..player.UserId
    DataStore:SetAsync(aID,player.leaderstats[currencyNameA].Value)
    DataStore:SetAsync(bID,player.leaderstats[currencyNameB].Value)
    print("Data saved")
end)

game:BindToClose(function()

    -- When game is ready to shutdown

    for i, player in pairs(game.Players:GetPlayers()) do
        if player then
            player:Kick("This game is shutting down or restarting!")
        end
    end

    wait(5)

end) 
0
I think in lines 20 and 21 you Should use `currencyA.Name` and `currencyB.Name` because those are the name of the int values but not the name of any particular variable Fad99 286 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

In all honesty and majesty lol your game should be configured from the site to allow api services. Secondly your requests must be pcall style. If you have a problemo, be sure to reply. Lastly, why don't you test this in other places? Does it repeat with same issues as before from output window...

0
at first api is on on the site. and im just starting to build a game but im stuck with the date load and save service. when there is no date i get the new player part. when i say value from coins and gold = 10 on new player it do save it and load it. but when im in game and i set value to 20 with the explorer in game the currency shows 20 but when i go offline it should save 20 but i doesnt. User#27824 0 — 5y
0
and what do u mean with the pcal style. im just starting with scripting so i have lots to learn. i copyed this from a tutorial and in the tutorial he shows it work but why doesnt it work with me? User#27824 0 — 5y
0
I can tell that's why there isn't anything to teach other than ctrl + z is undo and ctrl + x is cut which also allows paste like ctrl + c then ctrl + v Sapppower 17 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Solved

Gues they dont use this any more and now use DataStore2

Answer this question