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

data store service isn't saving?

Asked by 4 years ago
local DSS = game:GetService("DataStoreService")

local PlayerCash = DSS:GetDataStore("Tix")

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Folder = Instance.new("Folder")
        Folder.Name = "Data"
        Folder.Parent = Player
        local Cash = Instance.new("IntValue")
        Cash.Name = "Tix"
        Cash.Parent = Player.Data
        Cash.Value = PlayerCash:GetAsync(Player.userId) or 0

        game.Players.PlayerRemoving:connect(function(Player)
            PlayerCash:SetAsync(Player.userId, Cash.Value)
        end)
    end)
end)

When I test out to see if it works, it doesn't save at all. If I change the intvalue, it changes. But when I stop studio to see if it worked and play it again. It sets back to zero.

0
You're doing players removing inside of player added? killerbrenden 1537 — 4y
0
Am I supposed to put them in separate scripts? yayimstrongforever 0 — 4y
0
No, just not inside of eachother. killerbrenden 1537 — 4y
0
So, you would take out the removing, and put it under the last end) killerbrenden 1537 — 4y
0
I mean it works its just that now theres an error saying "Value is not a valid member of GlobalDataStore." yayimstrongforever 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Do you have API services enabled?

If you already do then I don't know what's going on. However, I do have a script made by XxxLloyd061302xxX, my favorite youtuber.

local ds = game:GetService("DataStoreService"):GetDataStore("--Cash01")

game.Players.PlayerAdded:Connect(function(player)
    local key = "cash-"..player.userId
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats" -- Must be lowercase
    local currency = Instance.new("IntValue",folder)
    currency.Name = "Money"
    currency.Value = 0

    local save = ds:GetAsync(key)
    if save then
        currency.Value = save
    end
    currency.Changed:Connect(function()
        ds:SetAsync(key,currency.Value)
    end)
end)

You can chose to use it or not. I just thought I might put this up here for others with the same question. Subscribe to the script maker here

Best wishes, Jail

0
I have API services turned on. But this script works for me. Thank you! yayimstrongforever 0 — 4y
Ad

Answer this question