Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to update a Module Variable?

How to update a Module Variable? explanation below

--module script
module={}

pose = "idle"

module.one = function()
print(pose)
if pose == "walk" then
--do stuff and
module.two()
end
end

module.two= function()
if pose == "walk" then
--do stuff and
module.one()
end
end
return module
--Local script
--require stuff so S = module script
S.pose = "walk" --So I change the variable first, then call the function
S.one()  --but the function says pose == idle when I just changed it .-.

1 answer

✓ Accepted answer

Careful.

Your ModuleScript doesn't ask for module.pose. It just has pose as a global variable.

If you want to be able to modify it from the outside, you should use instead refer to module.pose within the ModuleScript (which the other scripts can touch as in S.pose)


Nonetheless, I think it would be better to pass the pose as a parameter to a function, rather than modifying the variable directly.

1 comment

0

Thank you so much! Worked like a charm!

This discussion is preserved as it was. New answers, comments, and votes are closed.