Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you save values with a table?

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

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

1 comment

0

actually I am calling the module function, but it won't save, and I have api services on

This discussion is preserved as it was. New answers, comments, and votes are closed.