Module Scripts - Variable Error

I am currently using a module script located in replicated storage that holds many functions that I take from other scripts.

local module = {}
local variable = ""
local variable2=""
local variable3=""
module.myFunction = function()
    -- Function stuff that uses the variables above
end
return module

The module script is not running and it’s not giving me an error either. Am I supposed to put the variable definitions inside of every single function?
(I have print statements to test if every line is running, and they are)

2 Likes

Can you show us the part where you call the function?

local elevators = workspace.Elevators
local action = require(game.ReplicatedStorage.ElevatorScripts)
script.Parent.MouseButton1Click:Connect(function()
	if elevators.Elevator.Floor.Value == 2 and elevators.Elevator.currentlyMoving.Value == false then
		action:OpenUpperDoors()
	elseif elevators.Elevator.Floor.Value == 1 and elevators.Elevator.currentlyMoving.Value == false then
		elevators.Elevator.currentlyMoving = true
		action:ElevatorUp()
		action:OpenUpperDoors()
		elevators.Elevator.currentlyMoving = false
	else
		game.StarterGui.allGui.ElevatorError.Visible = true
	end
end)
1 Like

The modulescript isn’t committed, but I’m not sure if that affects the test run.

instead of action:ElevatorUp() try action.ElevatorUp()

2 Likes

Doens’t make sense but somehow worked! Thanks

3 Likes

It’s basically because you defined the function in the as module.myFunction and not module:myFunction()

1 Like

This is what I was thinking may have been the problem, but wasn’t entirely sure due to the fact they never showed how they defined the function

1 Like