Datastore not working with module script

A while ago I came across this same problem and shrugged off as a one time thing, but now a few months later the same problem arises if I make a module script and handle a datastore inside it. Nothing saves. There’s a small chance of it saving if the data is nil but any time after that it doesn’t work. Yet it seems to get the data fine.

Code:

local set = {
	["Scope"] = "_Xe12A";
	["DataStoreName"] = "MainStore";
	["KeySecurity"] = "113"
}

local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore(set.DataStoreName,set.Scope)
local sss = game:GetService("ServerScriptService")
local modules = sss:WaitForChild("ServerScripts")
modules = modules:WaitForChild("Modules")

local webhook = require(modules:WaitForChild("Webhooks"))

local http = game:GetService("HttpService")

local maxAttempts = 5


local ds = {}
	ds.UpdateData = function(...)
		print("Updating data")
		local uid,t = ...
		local attempts = 0
		repeat
			wait(1)
			local s,e = pcall(function()
				dataStore:SetAsync(uid.."_player_"..set.KeySecurity,http:JSONEncode(t))
			end)
		until s or attempts == maxAttempts
		if attempts == maxAttempts then
                      senddataerror(uid,t)
		end
	end
	
	ds.GetData = function(uid)
		local data = nil	
		repeat
			wait(1)
			local s,e = pcall(function()
				data = dataStore:GetAsync(uid.."_player_"..set.KeySecurity)
			end)
		until s
		if data then
			return http:JSONDecode(data)
		else
			return nil
		end
	end
return ds

(I had to remove a big chunk of the code as its for incase of data failures and it has private keys in it)

1 Like

Ok so uh I just realised what the issue was, I basically have a middle man script to control the module that gets fired from a bindable function, and the datastore module the save function requires 2 values the user id and the table to save, and so in my middle man I automatically unpacked the data. So in my function it was just trying to save data to a datastore with a table. Anyway sorry if this bumped it up. I just had to make this reply real quick.

First of all, I would believe the code should be webhook:senddataerror(uid, t).

Secondly, I would NOT suggest sending webhook posts to discord if that is what your webhook module is being used for as it can spam your discord webhook and potentially get it deleted.

Its server side only, and only gets called for bans made by admins.

and i removed the send data error function as it had private keys in it