hi i have 2 sets of code. My issue i here that event when module.setTrue() is triggered, my local script still keeps printing that the value of the variable in the module tim is false ( its doing this through the module.getTim() ). I have disabled the script and copied the code to a normal script, and it works fine. what’s the issue? thanks
(module.setTrue()is triggered in another script, but im very confident in it working as intended. local script is in playerscripts )
Local script code
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("ModuleScript"))
while true do
wait(0.2)
local result = module.getTim()
if result == true then
print("tim is true")
end
print(result)
end
Module script code
local module = {}
module.tim = false
function module:setTrue()
module.tim = true
end
function module:getTim()
return module.tim
end
return module
You use a colon for your functions while you’re attempting to call the function with the dot operator. Not 100% sure if that will fix it but I believe it’s related.
The script in the click detector I’m guessing is a server script whilst the playerscript one is local. So though they both require the same module the references held for them are unique to the contexts they are running on.
To handle this I would use a remote event to fire to all the relevant clients (and write a handler) which need that property to be updated in their copy of the module.
This would be a simple format for a remote handler on the client, which can be called from anywhere on the server.
It simply listens for the remote and runs an update function to change the property in the module.
--module
local mod ={}
mod.tim = false
mod.update = function(prop, val)
if mod[prop] then
mod[prop] = Val
end
end
Pathtoremote.onclientevent: Connect (mod.update)
return mod
Writing on phone, autocorrect may have misspelt things!
They mean that if you require the modulescript on the client, it’s not the same as when you require it on the server. They do not share the same values. Setting tim to true on the server would not set it to true in the modulescript you required on the client.
The solution to this would be to use a BoolValue for example that holds the value of Tim, and is shared across both the server and client. Then when you call setTrue you just set the value of the boolValue to true on the server, and it will automatically replicate to the client.