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

Data Store not saving/loading?

Asked by 4 years ago
Edited 4 years ago

I keep trying to use data store to save variables (which is fairly new to me) . I run the game, edit the variable, and re-start the game, and the DataStore brings up a value of 0. Here is my current code. Anyone have an idea as to what's wrong? EDIT: I have API in studio on. My guess is something to do with the player removed function at the end

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

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder")
    folder.Name = "stats"
    folder.Parent = player

    local Cash = Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Parent = folder
    Cash.Value = TutorialData:GetAsync(player.UserId) or 500
    TutorialData:SetAsync(player.UserId, 0)

    game.Players.PlayerRemoving:Connect(function(player)
        TutorialData:SetAsync(player.UserId, Cash)
        wait(1)
    end)
end)
0
line 13 you basically wipe all the data and set it to 0 greatneil80 2647 — 4y
0
Oh wow...:P thanks lol archerdancom -3 — 4y
0
Also , Please use 'pcall(function()' when Setting or Getting Data from DataStores. It would be dreadful to see your code error and fail during a game. Tizzel40 243 — 4y
0
In line 13 you set the data to 0 ~~~~~~~~~~~~~~~~~ TutorialData:SetAsync(player.UserId, 0) ~~~~~~~~~~~~~~~~~ dionsyran2 66 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Thanks to everyone :) this was answered by @greatneil80 and a tip by @Tizzel40 Thanks to you two!

Ad

Answer this question