#data store isnt working

1 messages · Page 1 of 1 (latest)

odd mason
#

so for some reason my datastore likes to almost never save and im not sure why like the folder is there and everything but just does not save

#
local dataStoreService = game:GetService("DataStoreService")
local leaderstats = dataStoreService:GetDataStore("leaderstats")

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player
    
    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Parent = folder
    
    local data
    
    local success, err = pcall(function()
        data = leaderstats:GetAsync(player.UserId)
        if not data then
            data = {0}
        end
    end)
    
    coins.Value = data[1]
end)

game.Players.PlayerRemoving:Connect(function(player)
    local coins = player:FindFirstChild("leaderstats"):FindFirstChild("Coins")
    
    leaderstats:SetAsync(player.UserId, {coins.Value})
end)```
unique moat
#

and

#

wait

#

nvm

#

any errors tho?

odd mason
odd mason
# unique moat any errors?

so first i get this when i close
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key

#

and i think thats it

unique moat
#

ok wtf did u do

#

how did u manage that

odd mason
#

wait so i have some more code

#
game.Players.PlayerAdded:Connect(petsModule.AddPlayer)
game.Players.PlayerRemoving:Connect(petsModule.RemovePlayer)```
#

that does this:

#
local module = {}

local dataStoreService = game:GetService("DataStoreService")
local leaderstats = dataStoreService:GetDataStore("leaderstats")

module.AddPlayer = function(Player: Player)
    local playerFolder = Instance.new("Folder")
    playerFolder.Name = "OwnedPets"
    playerFolder.Parent = Player
    
    local playerFolder2 = Instance.new("Folder")
    playerFolder2.Name = "EquippedPets"
    playerFolder2.Parent = Player
    
    local configurationFolder = Instance.new("Folder")
    configurationFolder.Name = "Configuration"
    configurationFolder.Parent = Player

    local hatchingValue = Instance.new("BoolValue")
    hatchingValue.Name = "Hatching"
    hatchingValue.Parent = configurationFolder
    hatchingValue.Value = false
    
    local data
    local success, error = pcall(function()
        data = leaderstats:GetAsync(Player.UserId)
    end)

    if not data or type(data) ~= "table" then
        data = {}
    end
    
    data["OwnedPets"] = data["OwnedPets"] or {}
    data["EquippedPets"] = data["EquippedPets"] or {}
        
    if error then
        warn(error)
    end
    
    for i, v in pairs(data["OwnedPets"]) do
        local tag = Instance.new("IntValue")
        tag.Name = v
        tag.Parent = playerFolder
    end
    
    for i, v in pairs(data["EquippedPets"]) do
        local tag = Instance.new("IntValue")
        tag.Name = v
        tag.Parent = playerFolder2
    end
end

module.RemovePlayer = function(Player: Player)
    local data = {}
    local owned = {}
    local equipped = {}
    
    for i, v in pairs(Player.OwnedPets:GetChildren()) do
        table.insert(owned, v.Name)
    end
    
    for i, v in pairs(Player.EquippedPets:GetChildren()) do
        table.insert(equipped, v.Name)
    end
    
    data["OwnedPets"] = owned
    data["EquippedPets"] = equipped
    
    leaderstats:SetAsync(Player.UserId, data)
end

return module
#

@unique moat but thats it

#

so im not sure how that works

unique moat
#

or smth

#

idk keep printing shit

#

actually wait

#

print(data[1])

odd mason
#

and save it ?

#

ill do this

local module = {}

local dataStoreService = game:GetService("DataStoreService")
local leaderstats = dataStoreService:GetDataStore("leaderstats")

module.AddPlayer = function(Player: Player)
    local playerFolder = Instance.new("Folder")
    playerFolder.Name = "OwnedPets"
    playerFolder.Parent = Player
    
    local playerFolder2 = Instance.new("Folder")
    playerFolder2.Name = "EquippedPets"
    playerFolder2.Parent = Player
    
    local configurationFolder = Instance.new("Folder")
    configurationFolder.Name = "Configuration"
    configurationFolder.Parent = Player

    local hatchingValue = Instance.new("BoolValue")
    hatchingValue.Name = "Hatching"
    hatchingValue.Parent = configurationFolder
    hatchingValue.Value = false
    
    local data
    local success, error = pcall(function()
        data = leaderstats:GetAsync(Player.UserId)
    end)

    if not data or type(data) ~= "table" then
        data = {}
    end
    
    data["OwnedPets"] = data["OwnedPets"] or {}
    data["EquippedPets"] = data["EquippedPets"] or {}
        
    if error then
        warn(error)
    end
    
    for i, v in pairs(data["OwnedPets"]) do
        local tag = Instance.new("IntValue")
        tag.Name = v
        tag.Parent = playerFolder
    end
    
    for i, v in pairs(data["EquippedPets"]) do
        local tag = Instance.new("IntValue")
        tag.Name = v
        tag.Parent = playerFolder2
    end
    print(data[1])
end

module.RemovePlayer = function(Player: Player)
    local data = {}
    local owned = {}
    local equipped = {}
    
    for i, v in pairs(Player.OwnedPets:GetChildren()) do
        table.insert(owned, v.Name)
    end
    
    for i, v in pairs(Player.EquippedPets:GetChildren()) do
        table.insert(equipped, v.Name)
    end
    
    data["OwnedPets"] = owned
    data["EquippedPets"] = equipped
    
    leaderstats:SetAsync(Player.UserId, data)
    print(data[1])
end

return module
unique moat
#

just print anywhere

odd mason
#

and nil again

#

this is when i dont have any data rn anyway

unique moat
#

at this point

#

just get

#

profileservice/store

#

u are better of using it anyways

odd mason
#

never heard of this

unique moat
#

prob better then u would ever make or need

odd mason
mighty graniteBOT
#

studio** You are now Level 8! **studio

unique moat
#

profile service