How would I make a simple datastore Module

I want to make a datastore system that's inside a module.

I've heard that people use modules for DataStores since its simple., but I'm not sure how they do it. I did go through the forums and found one example, but all of the others are too complex for me to work with, as I don't understand what they're doing.

The one example I looked through showed a simple way to use data stores, but I can’t really be flexible with it since it requires you to save with server scripts and I’m trying to save it on local scripts. I did rewrite everything so that it would be flexible with tables, but I’m not sure if it works since it’s not on a server script. I can provide the module that I’m working on.

DataStore Module:

local data = {}
local DataStoreService = game:GetService("DataStoreService")

function data.LoadData(Player, Value, valueName)
	print(Value)
	local dataStore = DataStoreService:GetDataStore(valueName)
	local data
	local success, errorMessage = pcall(function()
		data = dataStore:GetAsync(Player.UserId .. "_" .. valueName)
	end)

	if success and data then
		for i, newValue in Value do
			newValue.Value = data[i]
			print(newValue.Value,data[i])
		end
	else
		print(errorMessage)
		print(data)
	end
end

function data.SaveData(Player, Value, valueName)
	local dataStore = DataStoreService:GetDataStore(valueName)
	local success, errorMessage = pcall(function()
		data = dataStore:SetAsync(Playe`Preformatted text`r.UserId .. "_" .. valueName)
	end)
	
	if success then
		print("Successfully saved " .. Player .. "'s Data")
	end
end

function data.BindToClose(Value)
	print("Not Working")
end

return data

Wrong topic, should be in #help-and-feedback:scripting-support. And you can’t access DataStores on the client. If you want to save client data (which you really shouldn’t as it’d be unsecure), you would use RemoteEvents.

Okay. I understand about the topic issue, as it was supposed to be about how to get a datastore done. Although, I’ve should of mentioned that I’ve already tried using a remote

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.