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

How do you save values with a table?

Asked by
sad_eyez 162
6 years ago

I have already made a datastore inside a module, but for some reason it won't save with the table, and there is no errors, if anyone could help that'd be great

local module = {}
local datastore = game:GetService("DataStoreService"):GetDataStore("Data #1")

function module.load(plr)

    local overheadtron = plr:WaitForChild("Stats"):WaitForChild("OverheadTron").Value
    local tron = plr:WaitForChild("Stats"):WaitForChild("Tron").Value
    local tronc1 = plr:WaitForChild("Stats"):WaitForChild("TronCurve1").Value
    local tronc2 = plr:WaitForChild("Stats"):WaitForChild("TronCurve2").Value
    local theme = plr:WaitForChild("Stats"):WaitForChild("ThemeSong").Value

    local vc = plr:WaitForChild("Stats"):WaitForChild("VirtualCurrency").Value
    local nickname = plr:WaitForChild("Stats"):WaitForChild("Nickname").Value
    local hair = plr:WaitForChild("Stats"):WaitForChild("Hair").Value
    local mask = plr:WaitForChild("Stats"):WaitForChild("Mask").Value
    local shirt = plr:WaitForChild("Stats"):WaitForChild("Shirt").Value
    local pants = plr:WaitForChild("Stats"):WaitForChild("Pants").Value

    local values = {hair, mask, shirt, pants, vc, nickname, overheadtron, tron, tronc1, tronc2, theme}
    local savedTable = datastore:GetAsync(plr.userId.."-key")
    if savedTable ~= nil then
        values = savedTable
    end

end

function module.save(plr)
    local plrid = plr.userId

    local overheadtron = plr:WaitForChild("Stats"):WaitForChild("OverheadTron").Value
    local tron = plr:WaitForChild("Stats"):WaitForChild("Tron").Value
    local tronc1 = plr:WaitForChild("Stats"):WaitForChild("TronCurve1").Value
    local tronc2 = plr:WaitForChild("Stats"):WaitForChild("TronCurve2").Value
    local theme = plr:WaitForChild("Stats"):WaitForChild("ThemeSong").Value

    local vc = plr:WaitForChild("Stats"):WaitForChild("VirtualCurrency").Value
    local nickname = plr:WaitForChild("Stats"):WaitForChild("Nickname").Value
    local hair = plr:WaitForChild("Stats"):WaitForChild("Hair").Value
    local mask = plr:WaitForChild("Stats"):WaitForChild("Mask").Value
    local shirt = plr:WaitForChild("Stats"):WaitForChild("Shirt").Value
    local pants = plr:WaitForChild("Stats"):WaitForChild("Pants").Value

    local values = {hair, mask, shirt, pants, vc, nickname, overheadtron, tron, tronc1, tronc2, theme}
    datastore:SetAsync(plrid.."-key", values)

end

return module

1 answer

Log in to vote
0
Answered by 6 years ago

the problem is you probly never run this module, make sure a server script runs this (like this:)

local module = require(locationofmodule)

game.Players.PlayerAdded:connect(function(plr)
    local load = module.load(plr)
end)

while wait(120) do
    local save = module.save(plr)
end

0
actually I am calling the module function, but it won't save, and I have api services on sad_eyez 162 — 6y
Ad

Answer this question