If its in wrong category, then sorry I dont know where to put it
I am using SDM (Suphi’s datastore module) (I am actually just testing random things with it)
When I was using ProfileService I was requiring data module at script and then calling function to return player’s profile, but I do not know if its optimized or not
I’m thinking what is most optimized to share player’s data between server and server (Like from 1 script to other script)
I have these currently in mind but not sure what best and if there are better way
Through bindable events
or through function at data module
or through main module that just stores plr’s data (Using 1)
If you know a good way to share data from server to server then please tell me
make a folder on player named player data, store IntValues, String values, boolvalues, or any value in that folder and set them during player join, that’s how I do it, then get their value, pack them into array or dictionary, if dictionary, convert it into a string, then save it. i don’t use any modules soo idk how this method will work for it
Well when I was using profile service I wasn’t using any values
Everything was build on using remotes to get data (still optimized since I have cooldown on it and calling only when value is actually changed at server)
At server I was using the module which loads data to return the player data and then changing it
Still not sure if its optimized or not, but the values method sounds good (for tables ig I can use json encoding)
Personally I’d recommend using a module to store player data. Essentially all the module needs to do is return a table, then you can have one server script that’s dedicated to storing and removing the data, like in this example:
--!strict
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local PlayerData = require(ServerStorage.PlayerData)
local function onPlayerAdded(player: Player)
PlayerData[player.UserId] = -- The data you wish to store
end
local function onPlayerRemoving(player: Player)
PlayerData[player.UserId] = nil -- Remove the data if the player is leaving the game
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
And unless you have a system to control the order that server scripts run, you might run into a situation where attempting to fetch a player’s data from the module results in nil, which you can prevent by using a function that waits for the player’s data to be stored before returning it:
local function waitForPlayerData(userId: number)
while true do
local data = PlayerData[userId]
if data then return data end
task.wait()
end
end
So from what I understand, I can use module to store all player’s data (and remove it once they leave) then require it from any script and access it easily (Well ig that should work, not fully know about modules but enough to make things)
unless you have a system to control the order that server scripts run
Some developers prefer to use modules rather than individual scripts (with the exception of the script that requires the inital module), which has the benefit of allowing you to control which module runs first, therefore the order in which their code runs