Local module script nil

I have a module script located in starterplayerscripts, which stores a local variable for a value I use.

However, whenever I print it in any other local script even after requiring it, the table inside it is empty when it shouldn’t be.

I gave it a value when the server starts and when the server prints it the values show up, but on the local it’s just an empty table. I have no idea what’s going on.

-- Local Module in Starterplayerscripts --

local LSModule = {}


-- Holds all local data for player for future use
LSModule.DataStore = {}

LSModule.DataStore = {Stamina = nil, MaxStamina = nil}

return LSModule
-- Server script that sets the value of it --

	local UserID = Player.UserId
	
	if LocalStorageModule.DataStore.Stamina == nil then
		LocalStorageModule.DataStore.Stamina = PlayerData.PlayerDataStore[UserID].Stamina
		print(LocalStorageModule.DataStore.Stamina)
	end
	
	if LocalStorageModule.DataStore.MaxStamina == nil then
		LocalStorageModule.DataStore.MaxStamina = PlayerData.PlayerDataStore[UserID].MaxStamina
		print(LocalStorageModule)
	end
1 Like

You need to use a RemoteEvent or a RemoteFunction to communicate between client and server. Variables and tables and stuff won’t automatically synchronise between machines.

3 Likes

yep, what @hpgames16 said. listen to Jarod

1 Like

So I have to fire a remote event to fire the values from the server to the local module and then update the local module to match the values I fired?

1 Like

That is correct, but if this is for Stamina and MaxStamina and other low-risk player stats, you might want to keep them and manage them in the LocalScript.

1 Like

It’s all already managed on the server side because I don’t want people to exploit the stamina, the only reason I’m trying to sync it with the local version is so I can update my GUI seamlessly when stamina drains.

1 Like

if stamina is just for movement speed, and they can just disable any speed anticheat, I don’t see why it matters.

1 Like

Use FireClient or FireAllClients to exchange data from the server to individual clients then do whatever with that data client-side.

1 Like