Returning a value from a ModuleScript, which never changes


As said in the Title of the Topic, I am having a little issue with ModuleScripts.
I’ve spent maybe an hour trying to fix this, but i cant seem to find the issue.

The Problem

So what happens is the ModuleScript is told to change a value every second on the ServerSide, (Timer sorta thing) And then the Client is told to fetch the value from the ModuleScript. However, the Client is always recieving 30, instead of 29, 28 etc.

I can’t tell if this is a studio bug or not, since all other parts of this ModuleScript work fine, (by means of getting data from it ClientSide, and actually having the correct value)

The Code
--The Variables (table1, table2, etc. are not actually what is there, but there is the same amount of tables located in my script.)
local data = {
   local table1 = {},
   local table2 = {},
   local table3 = {},
   local table4 = {},
   local timer = 30

function data:ReturnTime() -- Function used for grabbing the time from Client Side

local value = data.timer
warn('Returning ' .. value)
return value

function data:CountDownTime()
warn('Timer Activated')
game.ReplicatedStorage.CallRoundBegin:FireAllClients() -- This tells the client to start asking for the value
for i = 1, 30 do -- Changes value on the Server Side
	data.timer = data.timer - 1

Thank you for any help in advance!

1 Like

Server changes to a module script do not replicate to the client, and vice-versa. If you want to do a countdown you should either have an “IntValue” in ReplicatedStorage, or send the number over a remote event.


I want to get some things right.

It is true, I am mistaken.

This is wrong, I think it is because of your method of returning them, I will write down an example of how you can make this.

-- ModuleScript
local data = {
   Timer = 30,

function data:StartTimer()
    for i = 1, 30 do
        data.Timer = data.Timer - 1
    data.Timer = 30 -- Resetting Timer

return data

-- Local Script that where you show your countdown
local data = require(PATH_TO_YOUR_MODULE)

   local textlabel.Text = data.Timer
-- There is obviously better ways to do this but this is just an example

You don’t have to write “local” in your tables.

It is not wrong, variables and other script contents are never replicated. I even tried the code you posted since you were so confident, but it doesn’t work that way.

I have wroten a round based minigame system which time was controlled similar like this by a module script. It was all working fine and it was replicating.

Edit: I have tested it myself just a second ago and it wasn’t working, I wanted to check the game I have made using module scripts to control time because I forgot how I used them but it was a commission game and I don’t have access to it anymore. Maybe I remember wrong how I used them. But in the end, it doesn’t works, I am sorry about that.

Edit2: I updated my first reply here to not confuse anyone else.

1 Like

The ‘local’ thing was just a blip by my brain- I tried the other method using ReplicatedStorage and it works fine.

1 Like