Problem with sending a required value of a module from client to server

so, im making the data system of my game, but my datas are client, and as maybe you know, datastore only works on server.
Then, im using remoteevents to like “ask” the value by a server script, that arives at a local, which sends it back the local version of the module value.

with a big resume of the video, when i click on the button on the screen, it prints the table as it was sopposed to be, i update one of the values of the table, and it prints right.
but, when i die (on roblox), it prints the old one value (just like it didnt got changed) but both them are printed on client scripts. one of my question is: why two clients of the same player have different “perspectives”

1 Like

This might be happening because when you die, the modified PlayerConfigs module is being destroyed. After respawning, the original PlayerConfigs script is placed into PlayerGui again with the value unchanged.

Taking a look at the documentation StarterGui | Documentation - Roblox Creator Hub, there’s a section that describes this behavior.

When a Player.Character respawns, the contents of their PlayerGui are emptied. Children of the StarterGui are then copied along with their descendants into the PlayerGui.

i dont think so, it prints before the player starts respawning

What’s printing before the player starts respawning?

so, the abiliy1 value (one of vars of the table) is initially “Q”, so then i set on my custom settings to “H”, and when i die, it prints with the Q…

I assume that’s because the script is getting destroyed and replaced with the original in StarterGui during the respawn process. In fact, you can see the client is printing “Sending Locally PlayerConfigs” after the server prints “Character Added” which makes me think the respawn has already happened and the modified module script was replaced with the original.

If that’s not the case though, then I’m not sure what would be causing this issue.

hmmm ok, i changed some things based on it, but im still on the problem. but thanks anyway!

Unlikely to be the main issue, but could contribute is that you’re sending a referenced table across the network (typically this is buggy or has unintended results).
Always ensure table data, especially from a module, if sent over a remote call, is a clean table that is dereferenced from the original.

--> USAGE :: Deepcopy(Table: {any}) -> {any}
local DeepCopy;function DeepCopy(Table)
	local Clone = {};
	for Index, Value in pairs(Table) do
		Clone[Index] = if typeof(Value) == "table" then DeepCopy(Value) else Value
	end
	return Clone
end

Also, setting to a datastore every single time this remote is called is awful code design; and introduces a vulnerability that could let exploiters cause mass data loss in your game via spamming said remote and overflowing your rate limit for datastores.

Cache data (per player) you do not explicitly need to write to the cloud in a table on the server, then write that cache to the datastore on both an interval (30 to 60 seconds usually) and when that player leaves.