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

DataStore Not Saving/Loading?

Asked by 10 years ago

It does not print any error whatsoever. Script is in ServerScriptStorage of course I added prints so it just prints the values it just prints "" and "0" "" for the StringValue and "0" for the NumberValue Yes I edited the values of the items so it has something to save...

wait()
local DataStoreService = game:GetService("DataStoreService")
local SafeStore = game.ReplicatedStorage:FindFirstChild("PlayersData")
game.Players.PlayerAdded:connect(
function(Player) 
    local PlayerStore = DataStoreService:GetDataStore(tostring(Player.userId), "PlayerData")
    -----
    ----Start Of Client Store
    local PlayerTag = Instance.new("StringValue",SafeStore)
    PlayerTag.Value = Player.userId
    PlayerTag.Name = (Player.userId)
    print(PlayerTag.Name)
    ------
    local DataStore = Instance.new("Folder",PlayerTag)
    DataStore.Name = "Data"
    ------Player load
    local SlotHold = Instance.new("Folder",DataStore)
    SlotHold.Name = "SlotHold"
    -------------------Slot One VVVVV
    local SlotOne = Instance.new("Folder",SlotHold)
    SlotOne.Name = "Slot1"
    --
    local SlotOneName = Instance.new("StringValue",SlotOne)
    SlotOneName.Name = "ItemName"
    SlotOneName.Value = PlayerStore:GetAsync("SlotOneName")
    print(SlotOneName.Value)
    --
    local SlotOneStock = Instance.new("NumberValue",SlotOne)
    SlotOneStock.Name = "ItemStock"
    SlotOneStock.Value = PlayerStore:GetAsync("SlotOneStock")
    local SlotOneUsed = Instance.new("BoolValue",SlotHold)
    SlotOneUsed.Name = "Slot1Used"
    print(SlotOneStock.Value)
    ----
    local SlotOneUsedSlot = Instance.new("StringValue",SlotOneUsed)
    SlotOneUsedSlot.Name = "Slot"
    SlotOneUsedSlot.Value = (SlotOne.Name)
    ---
    if SlotOneName.Value == "" and SlotOneStock.Value <= 0 then
        SlotOneUsed.Value = false
    else
        SlotOneUsed.Value = true
    end
    -------------------Slot One^^ 
    -------------------Slot Two VVVVV
    local SlotTwo = Instance.new("Folder",SlotHold)
    SlotTwo.Name = "Slot2"
    --
    local SlotTwoName = Instance.new("StringValue",SlotTwo)
    SlotTwoName.Name = "ItemName"
    SlotTwoName.Value = PlayerStore:GetAsync("SlotTwoName")
    print(SlotTwoName.Value)
    --
    local SlotTwoStock = Instance.new("NumberValue",SlotTwo)
    SlotTwoStock.Name = "ItemStock"
    SlotTwoStock.Value = PlayerStore:GetAsync("SlotTwoStock")
    print(SlotTwoStock.Value)
    -----
    local SlotTwoUsed = Instance.new("BoolValue",SlotHold)
    SlotTwoUsed.Name = "Slot2Used"
    -----
    local SlotTwoUsedSlot = Instance.new("StringValue",SlotTwoUsed)
    SlotTwoUsedSlot.Name = "Slot"
    SlotTwoUsedSlot.Value = (SlotTwo.Name)
    -----
    if SlotTwoName.Value == "" and SlotTwoStock.Value <= 0 then
        SlotTwoUsed.Value = false
    else
        SlotTwoUsed.Value = true
    end
    -------------------Slot Two^^^^
    -------------------Slot Three VVVVV
    local SlotThree = Instance.new("Folder",SlotHold)
    SlotThree.Name = "Slot3"
    --
    local SlotThreeName = Instance.new("StringValue",SlotThree)
    SlotThreeName.Name = "ItemName"
    SlotThreeName.Value = PlayerStore:GetAsync("SlotThreeName")
    print(SlotThreeName.Value)
    --
    local SlotThreeStock = Instance.new("NumberValue",SlotThree)
    SlotThreeStock.Name = "ItemStock"
    SlotThreeStock.Value = PlayerStore:GetAsync("SlotThreeStock")
    print(SlotThreeStock.Value)
    -----
    local SlotThreeUsed = Instance.new("BoolValue",SlotHold)
    SlotThreeUsed.Name = "Slot3Used"
    ----
    local SlotThreeUsedSlot = Instance.new("StringValue",SlotThreeUsed)
    SlotThreeUsedSlot.Name = "Slot"
    SlotThreeUsedSlot.Value = (SlotThree.Name)
    ----
    if SlotThreeName.Value == "" and SlotThreeStock.Value <= 0 then
        SlotThreeUsed.Value = false
    else
        SlotThreeUsed.Value = true
    end
    -------------------Slot Three ^^^^
    repeat wait() until SafeStore:findFirstChild(Player.userId)
    local PlayerData = SafeStore:findFirstChild(Player.userId)
    repeat wait() until PlayerTag:findFirstChild("Data")
    ------
    DataStore:Clone().Parent = Player
end) 
-----UpdateAsync
game.Players.PlayerRemoving:connect(function(Player)
    local PlayerStore = DataStoreService:GetDataStore(tostring(Player.userId), "PlayerData")
    local PlayerData = SafeStore:findFirstChild(Player.userId)
    local PlrData = Player.Data.SlotHold
    if SafeStore:findFirstChild(Player.userId) then
        PlayerStore:SetAsync("Slot1Name", PlrData.Slot1.ItemName.Value)
        print(PlrData.Slot1.ItemName.Value)
        PlayerStore:SetAsync("Slot1Stock", PlrData.Slot1.ItemStock.Value)
        print(PlrData.Slot1.ItemStock.Value)
        -----SlotOne
        PlayerStore:SetAsync("Slot2Name", PlrData.Slot2.ItemName.Value)
        print(PlrData.Slot2.ItemName.Value)
        PlayerStore:SetAsync("Slot2Stock", PlrData.Slot2.ItemStock.Value)
        print(PlrData.Slot2.ItemStock.Value)
        ----SlotTwo
        PlayerStore:SetAsync("Slot3Name", PlrData.Slot3.ItemName.Value)
        print(PlrData.Slot3.ItemName.Value)
        PlayerStore:SetAsync("Slot3Stock", PlrData.Slot3.ItemStock.Value)
        print(PlrData.Slot3.ItemStock.Value)
        ----SlotThree
        SafeStore:findFirstChild(Player.userId):remove()
        print(Player.Name .. " Saved")
    end
end)
----10
game.OnClose = function()
    wait(5)
end

Answer this question