Hello devs! I have come across a bug in my script that I have no idea how to work around.
The script:
PlayCurrentDialog.OnClientEvent:Connect(function(Name)
print(Name) --Prints
local DialogModule = require(game.ReplicatedStorage.Dialog[Name])
print("Required") --Doesn't print
local DialogTable = DialogModule["Current Dialog"]
DialogFunctions["PlayDialog"](DialogTable)
end)
There are no errors in output.
I have also checked if the modulescript exists and it does:
local ModuleScript = game.ReplicatedStorage.Dialog:FindFirstChild(Name)
if ModuleScript and ModuleScript:isA(ModuleScript) then
print("Exists") --Prints
end
use ReplicatedStorage.Dialog:FindFirstChild() instead of ReplicatedStorage.Dialog[Name]
you should also use an if statement to make sure it finds the module, and if it does require it :^)
Whats the module code? Because a module must run all the code in it before it returns so if you have a loop that does not end. Require wont work. It will just pause the thread forever.
What is likely happening here is that āDialogā is an instance, and when indexing it with āNameā what youāre actually doing is getting the name of that instance, and not getting the child of that instance. Either change āNameā to something else, like āModuleā, or use :FindFirstChild(Name)
Have you tried printing what game.ReplicatedStorage.Dialog[Name] actually is?
Okay I identified the problem: inside my ModuleScripts I was requiring other ModuleScripts (which causes an infinite loop like @ineed_massnow said) , I used Bindable Functions so the ModuleScripts could communicate with each other without breaking the main script.
It does give a property if the query is a property name. This method is pretty useful in certain situations (storing a number of properties in a table and then iterating through said table to change properties of an object).
It actually checks for a property before checking for a child instance.
For example, if you put a folder into workspace and name it āNameā then:
print(workspace["Name"]);
will print out āworkspaceā in the output window, disregarding the folder that you created.