A lil problem with data store script

The one that is not indented and has * is the line that causes the error

--//Services\\

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

--//Settings\\

local MoneyDataStore = DataStoreService:GetOrderedDataStore("MoneyData", 0)
local DataStore = DataStoreService:GetDataStore("NormalData", 0)

local Values = {
	Money = {
		Name = "Money",
		Type = "NumberValue",
		Value = 0,
		DS = MoneyDataStore,
		Parent = "IntValue"
	},
}

--//Functions\\

function SaveAsync(DataStore, Key, Value)
	local succ, err = pcall(function()
		DataStore:SetAsync(Key,Value)
	end)
	wait(5)
	if not succ then
		SaveAsync(DataStore, Key, Value)
	end
	return
end

function LoadValues(player)
	local FolderStats = Instance.new("Folder")
	FolderStats.Name = "FolderStats"
	FolderStats.Parent = player

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

	for i,Value in pairs(Values) do
		local Val = Instance.new(Value.Type)
		Val.Name = Value.Name
		Val.Value = Value.DS:GetAsync(player.Name..Value.Name) or Value.Value

		if Value.Parent == "IntValue" then
			Val.Parent = leaderstats
		else
			Val.Parent = FolderStats
		end
	end
end

function SaveValues(player)
	for i,Value in pairs(player.FolderStats:GetChildren()) do
		spawn(function()
			SaveAsync(Values[Value.Name].DS, player.Name..Value.Name, Value.Value)
		end)
	end
	for i,Value in pairs(player.leaderstats:GetChildren()) do
		spawn(function()

*SaveAsync(Values[Value.Name].DS, player.Name..Value.Name, Value.Value)*

end)
	end
end

function ServerClosing()
	for i,player in pairs(Players:GetChildren()) do
		player:Kick("Server shutting down.")
	end
	wait(5)
end

--//Events\\

game:BindToClose(ServerClosing)

Players.PlayerAdded:Connect(LoadValues)

Players.PlayerRemoving:Connect(SaveValues)

Output:

  19:44:52.033  ServerScriptService.moeny:64: attempt to index nil with 'DS'  -  Server - moeny:64
  19:44:52.033  Stack Begin  -  Studio
  19:44:52.034  Script 'ServerScriptService.moeny', Line 64  -  Studio - moeny:64
  19:44:52.034  Stack End  -  Studio
1 Like

Typo??

its the name of the script the moeny

1 Like