I created a wrapper for Suphis Datastore and it was intended to be used from a bindable function where any service could use the data but whenever I try to call it, it trys to return the datastore but returns nil instead
This returns nil
local dataStore = game:GetService('ServerScriptService').Engine.Triggers.Function_OpenData:Invoke(player)
This attempts to send the datastore (I have checked right before the return printing it and yes it does print the datastore)
function OpenData(player)
assert(type(player) == 'userdata', '[DataServer]: Argument must be a player')
--// Open and return the players data
local dataStore = dataStorePackage.new(activeSecret, player.UserId)
dataStore.StateChanged:Connect(StateChange) StateChange(dataStore.State, dataStore)
return dataStore
end
Im not sure as to what is going on, any help is appreciated
This wont work because bindable functions don’t return the same table they return a clone
so this means when you do
return dataStore
its not returning the same datastore that’s inside the module but a clone of it
so to fix this problem instead of using a bindable function you can use a modulescript or save your custom function inside the datastore object it self
local module = {}
function module.OpenData(player)
local dataStore = dataStorePackage.new(activeSecret, player.UserId)
dataStore.StateChanged:Connect(StateChange) StateChange(dataStore.State, dataStore)
return datastore
end
return module
local ServerScriptService = game:GetService('ServerScriptService')
local datastore = require(ServerScriptService.ModuleScript).OpenData(player)
But SDM was designed in a way where you should not need to use a wrapper its ok to interact with SDM directly from all your scripts using a wrapper will technically downgrade your user experience with the SDM module and add unneeded complexity