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

DataStores won't save player's progress?

Asked by 5 years ago

So while I was testing my game, I noticed that these DataStores won't work. I had tested it a lot not on Studio, but with different alt. accounts for DataStore testing. Can someone tell me what's wrong with this script?

local dataStores = game:GetService("DataStoreService"):GetDataStore("BitsDataStore")
local defaultBits = 0
local playersLeft = 0

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

    playersLeft = playersLeft + 1

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

    local bits = Instance.new("IntValue")
    bits.Name = "Bits"
    bits.Value = 0
    bits.Parent = leaderstats

    player.CharacterAdded:Connect(function(character)
        character.Humanoid.WalkSpeed = 16
        character.Humanoid.Died:Connect(function()
            -- Whenever someone dies, this event will run

            if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
                game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
            end

            if character:FindFirstChild("GameTag") then
                character.GameTag:Destroy()
            end

            player:LoadCharacter()
        end)
    end)

    -- Data stores

    local player_data 

    pcall(function()
        player_data = dataStores:GetAsync(player.UserId.."-Bits") -- 1736284-Bucks
    end)

    if player_data ~= nil then
        -- Player has saved data, load it in
        bits.Value = player_data
    else
        -- New player
        bits.Value = defaultBits
    end

end)

local bindableEvent = Instance.new("BindableEvent")

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

    pcall(function()
        dataStores:SetAsync(player.UserId.."-Bits",player.leaderstats.bits.Value)
        print("Saved")
        playersLeft = playersLeft - 1
        bindableEvent:Fire()
    end)

end)

game:BindToClose(function()
    -- This will be triggered upon shutdown
    while playersLeft > 0 do
        bindableEvent.Event:Wait()
    end
end)
0
what did i say about watching alvinbloxx User#24403 69 — 5y
0
I heard there is a DataStore problem on Roblox, and there is no solution yet. Roblox has been very transparent about this. It's on their top priority to fix DataStores. saSlol2436 716 — 5y
0
Oh, ok! Didn't knew that there is a DataStore problem. User#25852 0 — 5y
0
and incapaxx is not my dad User#25852 0 — 5y

Answer this question