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

Why it won't save cash to DataStore?

Asked by 7 years ago

Hey, i have problem with DataStore. I think it should works fine, but it says always "no data found"..

Here is script:

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

game.Players.PlayerAdded:connect(function(player)
    if script.Parent.SettingsTab.CashSave.Value == true then
        pcall(function()
            local store = DataStore:GetAsync("u_"..player.userId)
            if store then
                print("Found cash data")
                PlayerStats.Value = store
            else
                print ("No data found")
            end
        end)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if script.Parent.SettingsTab.CashSave.Value == true then
        pcall(function()
            DataStore:SetAsync("u_"..PlayerStats.Value)
            print("Saved")
        end)
    end
end)

It's not entire script, because script is long.

1 answer

Log in to vote
0
Answered by 7 years ago

In line 20, you only specified the key, not the value. You need to provide the value for it to set as well!

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

game.Players.PlayerAdded:connect(function(player)
    if script.Parent.SettingsTab.CashSave.Value == true then
        pcall(function()
            local store = DataStore:GetAsync("u_"..player.UserId) -- Also, stop using deprecated stuff! It is a bad habit!
            if store then
                print("Found cash data")
                PlayerStats.Value = store
            else
                print ("No data found")
            end
        end)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if script.Parent.SettingsTab.CashSave.Value == true then
        pcall(function()
            DataStore:SetAsync("u_"..player.UserId, PlayerStats.Value) -- There, this should work!
            print("Saved")
        end)
    end
end)

Any questions? Please leave a comment below. Thanks!

0
Oh.. okay, works fine. Thank you. Anyway that was my first time with DataStores lol karolus1 8 — 7y
Ad

Answer this question