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

Data Store not working, no output or errors? Need a fresh pair of eyes. (SOLVED)!

Asked by
z_lm 9
2 years ago
Edited 2 years ago

I really try to not post on here to not waste anyone's time, but I've been trying to take a crack at this and I'm at a crossroads.

Datastore used to work, but now today it all of a sudden doesn't. I was updating my game but can't think of any major changes I've done rather than adding a couple of things to the table to save. Maybe one of you guys will see something that I don't.

Sorry that there are so many BoolValues being added, I didn't know how to condense it to make it neater. I did make a dictionary in a module script but didn't know how to incorporate it.

Edit: SOLVED! I only ever had my datastore save when a player left, this made it hard to see if there were any errors in general. If you're having trouble, try saving it with a remote. This made me realize that the title "Lenny" was named incorrectly.

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")

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

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

    local titles = Instance.new("Folder")
    titles.Name = "Titles"
    titles.Parent = player.Shop

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


    -----------------------TITLES

    local Poor = Instance.new("BoolValue")
    Poor.Name = "Poor"
    Poor.Parent = player.Shop.Titles

    local Fighter = Instance.new("BoolValue")
    Fighter.Name = "Fighter"
    Fighter.Parent = player.Shop.Titles

    local Scout = Instance.new("BoolValue")
    Scout.Name = "Scout"
    Scout.Parent = player.Shop.Titles

    local Cool = Instance.new("BoolValue")
    Cool.Name = "Cool"
    Cool.Parent = player.Shop.Titles

    local Sk8r = Instance.new("BoolValue")
    Sk8r.Name = "Sk8r"
    Sk8r.Parent = player.Shop.Titles

    local Fearless = Instance.new("BoolValue")
    Fearless.Name = "Fearless"
    Fearless.Parent = player.Shop.Titles

    local Princess = Instance.new("BoolValue")
    Princess.Name = "Princess"
    Princess.Parent = player.Shop.Titles

    local Nemesis = Instance.new("BoolValue")
    Nemesis.Name = "Nemesis"
    Nemesis.Parent = player.Shop.Titles

    local Worthy = Instance.new("BoolValue")
    Worthy.Name = "Worthy"
    Worthy.Parent = player.Shop.Titles

    local Lenny = Instance.new("BoolValue")
    Lenny.Name = ":-)"
    Lenny.Parent = player.Shop.Titles

    local Wealthy = Instance.new("BoolValue")
    Wealthy.Name = "Wealthy"
    Wealthy.Parent = player.Shop.Titles

    local Godly = Instance.new("BoolValue")
    Godly.Name = "Godly"
    Godly.Parent = player.Shop.Titles

    --------------EFFECTS
    local Medic = Instance.new("BoolValue", player.Shop.Effects)
    Medic.Name = "Medic"
    Medic.Value = false

    local Stars = Instance.new("BoolValue")
    Stars.Name = "Stars"
    Stars.Parent = player.Shop.Effects

    local Music = Instance.new("BoolValue")
    Music.Name = "Music"
    Music.Parent = player.Shop.Effects

    local Hearts = Instance.new("BoolValue")
    Hearts.Name = "Hearts"
    Hearts.Parent = player.Shop.Effects

    local Lightning = Instance.new("BoolValue")
    Lightning.Name = "Lightning"
    Lightning.Parent = player.Shop.Effects

    local Virus = Instance.new("BoolValue")
    Virus.Name = "Virus"
    Virus.Parent = player.Shop.Effects

    local Lava = Instance.new("BoolValue")
    Lava.Name = "Lava"
    Lava.Parent = player.Shop.Effects

    local Interstellar = Instance.new("BoolValue")
    Interstellar.Name = "Interstellar"
    Interstellar.Parent = player.Shop.Effects



    -------------------

    local Money = Instance.new("IntValue")
    Money.Name = "Money"
    Money.Parent = leaderstats

    local Wins = Instance.new("IntValue")
    Wins.Name = "Wins"
    Wins.Parent = leaderstats

    local Check = Instance.new("IntValue", player)
    Check.Name = "Check"
    Check.Value = 0

    local TotalBroken = Instance.new("IntValue", player)
    TotalBroken.Name = "TotalBroken"
    TotalBroken.Value = 0


    local playerUserId = "Player_"..player.UserId
    -- Load Data
    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(playerUserId)
    end)

    if success then
        if data then
            Money.Value = data.Money
            Wins.Value = data.Wins
            Poor.Value = data.Poor
            Fighter.Value = data.Fighter
            Scout.Value = data.Scout
            Cool.Value = data.Cool
            Sk8r.Value = data.Sk8r
            Fearless.Value = data.Fearless
            Princess.Value = data.Princess
            Nemesis.Value = data.Nemesis
            Worthy.Value = data.Worthy
            Lenny.Value = data.Lenny
            Wealthy.Value = data.Wealthy
            Godly.Value = data.Godly
            Medic.Value = data.Medic
            Stars.Value = data.Stars
            Music.Value = data.Music
            Hearts.Value = data.Hearts
            Lightning.Value = data.Lightning
            Virus.Value = data.Virus
            Lava.Value = data.Lava
            Interstellar.Value = data.Interstellar
end
end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local playerUserId = "Player_"..player.UserId
    local data = {
        Money = player.leaderstats.Money.Value;
        Wins = player.leaderstats.Wins.Value;
        Poor = player.Shop.Titles.Poor.Value;
        Fighter = player.Shop.Titles.Fighter.Value;
        Scout = player.Shop.Titles.Scout.Value;
        Cool = player.Shop.Titles.Cool.Value;
        Sk8r = player.Shop.Titles.Sk8r.Value;
        Fearless = player.Shop.Titles.Fearless.Value;
        Princess = player.Shop.Titles.Princess.Value;
        Nemesis = player.Shop.Titles.Nemesis.Value;
        Worthy = player.Shop.Titles.Worthy.Value;
        Lenny = player.Shop.Titles.Lenny.Value;
        Wealthy = player.Shop.Titles.Wealthy.Value;
        Godly = player.Shop.Titles.Godly.Value;
        Medic = player.Shop.Effects.Medic.Value;
        Stars = player.Shop.Effects.Stars.Value;
        Music = player.Shop.Effects.Music.Value;
        Hearts = player.Shop.Effects.Hearts.Value;
        Lightning = player.Shop.Effects.Lightning.Value;
        Virus = player.Shop.Effects.Virus.Value;
        Lava = player.Shop.Effects.Lava.Value;
        Interstellar = player.Shop.Effects.Interstellar.Value;

    }



    local success, errormessage = pcall(function()
        myDataStore:SetAsync(playerUserId, data)
    end)

    if success then
        print("Data saved!")
    else
        print("There was an error when saving data.")
        warn(errormessage)
    end

end)

Answer this question