Module scripts not doing

hi, im not sure why this doesnt work. I have another script printing the value of time every 0.2 seconds, and have a click detector using module.setTrue() . My click detect works fine, but after i click it, my first script is still printing that “tim” is false.

note that no errors are thrown and my first “tim printing” script is a local one, but i have put the module script in replicated storage , so it should be able to use it

local module = {}
tim = false

function module:setTrue()
	module.tim = true
	print(module.tim)
end

function module:getTim()
	print("tim", module.tim)
	return module.tim
end

return module
1 Like

Is the script that detects the “.Clicked” event a server script?

Tim variable is not in the module

local module = {tim}
module.tim = false

He uses module.tim everywhere, so it doesn’t change really much until false value is needed instead of the nil one.

I’m assuming that he set value in the server side and tries to receive it on the client side, so that’s why it doesn’t work.

But he did not insert tim value into the module table, only in the script

How do local variables in modules work?

Module scripts are quite straightforward. Y
They are basically rental functions. Anyone can use them to do whatever they want with them.
That means that they borrow the behaviour from what calls them. A localscript calls a module: the module behaves like a localscript.

So you can think of it like this: every client has a module of their own, and the server has one too. Like a local database. You need to be consistent with the place where you’re calling the module from throughout the game if you want it to function the way you want it to

That’s the problem only in case of using module:getTim() function because there’s no child with index tim in the table, so it returns nil instead of false.

You’re absolutely right that, it should be declared in the table before functions, but maybe the actual problem here is that he tries to index table changes on different sides, which is impossible

You can add a function to your module, print function. It will work if you call it from the same client/server. But it doesn’t change the behaviour of the modulescript at all. You should still keep in mind the server replication stuff

problem is something else … the script worked fine :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.