Any idea why my modulescript doesn't work?

I am trying to make a button that opens a door, with the door and button being separate models. I am using a modulescript stored in ServerScriptService that contains tween functions to open the door, and I am using a regular script in the button that will use the functions in the modulescript to play the tween when the button is pressed. I have searched all over YouTube for tutorials on modulescripts, but I can’t seem to understand exactly how they work. Any help is appreciated!


(ModuleScript for the door, it is in the ServerScriptService.)

(Script for the button, I am attempting to call the functions in the modulescript.

This is what you are trying to do:

local Module = require(script.Parent.ModuleScript)
GateBButton = game.Workspace.GateBButton
GateBButton.MouseClick:Connect(Module.GateBOpen)

If your ModuleScript is in ServerScriptService your require should be:

local Module = require(game:GetService("ServerScriptService"):WaitForChild("ModuleScript")

script.Parent would be your button so you actually should be getting an error telling you there is no ModuleScript in the button. Make sure when you test things you have the output from the View menu selected to see errors that are occurring.

Hello @KCavileer you need to use require() for this!

local doorModule = require(script.Parent:WaitForChild("ModuleScript"))
local GateBButton = workspace.GateButton

GateButton.MouseClick:Connect(function()
doorModule.GateBOpen()
end)

To make a model script work, You have to do something like this
In a diffrent script, Get the location of your ModelScript.

Next, to call a function inside the Model Script, your going to need to use Require, and the name of the function that you created inside the model script.


Your module script is not working because you are not calling the function in the model script. Create a name for a function in your ModelScript, and call it like How I did above. I also highly recommend if your using a ModelScript to put it in Replicated Storage so you can call it from anywhere.