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

Why won't this datastore script save anything?

Asked by
Viking359 161
6 years ago

I can't figure out what's wrong with it, but this server script isn't working.

local DSS = game:GetService("DataStoreService")

local datastore = DSS:GetDataStore("GeneralSaveData", "Players")

function generateDataKey(player)
    local ret = "uid_" .. player.userId
    return ret
end

function generateDataTable(player)
    local dataTable = {}
    for _, tool in ipairs(player.Backpack:GetChildren()) do
        table.insert(dataTable, tool.Name)
    end
    return dataTable
end

function saveDataForPlayer(player)
    local key = generateDataKey(player)
    local data = generateDataTable(player)
    datastore:SetAsync(key, data)
end

function inputDataToPlayer(player, data)
if data then
for _,T in pairs(data) do
    if game.ServerStorage.Weapons:FindFirstChild(T) then
    local wep = game.ServerStorage.Weapons:FindFirstChild(T)
        wep:Clone().Parent = player.StarterGear
        wep:Clone().Parent = player.Backpack
    end
end
end
end

function loadDataForPlayer(player)
    local key = generateDataKey(player)
    local data = datastore:GetAsync(key)
    inputDataToPlayer(player, data)
end

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

game.Players.PlayerRemoving:Connect(saveDataForPlayer) 

What's wrong with it and how do I fix it?

0
player added event? abnotaddable 920 — 6y
0
print debugging? abnotaddable 920 — 6y

Answer this question