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

First time using a ModuleScript. How do I stop this error?

ModuleScript:

function OpenDoor(LO, RO, LC, RC, FLOOR)
	print("YAY")
	local TweenService = game:GetService("TweenService")
	local TweenINFO = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
	local OpenLeft = {CFrame = CFrame.new(LO)*CFrame.Angles(0,math.pi/2,0)}
	local OpenRight = {CFrame = CFrame.new(RO)*CFrame.Angles(0,math.pi/2,0)}
	local ClosedRight = {CFrame = CFrame.new(LC)*CFrame.Angles(0,math.pi/2,0)}
	local ClosedLeft = {CFrame = CFrame.new(RC)*CFrame.Angles(0,math.pi/2,0)}
	if workspace.ElevatorRoom.OnFloor.Value ~= FLOOR then
		repeat wait() until workspace.ElevatorRoom.OnFloor.Value == FLOOR 
	elseif workspace.ElevatorRoom.OnFloor.Value == FLOOR and script.Parent.Open.Value == false then
		local openleft = TweenService:Create(script.Parent.Parent.ElevatorFrame.Left, TweenINFO, OpenLeft)
		local openright = TweenService:Create(script.Parent.Parent.ElevatorFrame.Right, TweenINFO, OpenRight)
		script.Parent.Open.Value = true
		openleft:Play()
		openright:Play()
		for i = 5, 1, -1 do
			print(i)
			wait(1)
		end
		local closeleft = TweenService:Create(script.Parent.Parent.ElevatorFrame.Left, TweenINFO, ClosedRight)
		local closeright = TweenService:Create(script.Parent.Parent.ElevatorFrame.Right, TweenINFO, ClosedLeft)
		closeleft:Play()
		closeright:Play()
		script.Parent.Open.Value = false
	end
	print("Ended")
end

return OpenDoor()

script:

local OpenDoor = require(workspace.ModuleScript)
script.Parent.ClickDetector.MouseClick:Connect(function()
	OpenDoor(
		13.7, 4.4, 35.351,
		13.7, 4.4, 48.451,
		13.7, 4.4, 44.35,
		13.7, 4.4, 39.45,
		1		
		)
end)

errors: 16:51:20.097 - Workspace.ModuleScript:6: bad argument #1 to 'new' (Vector3 expected, got nil) 16:51:20.110 - Requested module experienced an error while loading

any help is greatly appreciated

1 comment

0

You should probably be returning OpenDoor instead of OpenDoor() at the end of your module. Otherwise, you're going to return OpenDoor() whenever you require the module. Since it's calling OpenDoor() with no args, it throws an error.

1 answer

--Module Script --
local OpenDoorFunction = {}
function OpenDoorFunction.OpenDoor(LO, RO, LC, RC, FLOOR)
    print("YAY")
    local TweenService = game:GetService("TweenService")
    local TweenINFO = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
    local OpenLeft = {CFrame = CFrame.new(LO)*CFrame.Angles(0,math.pi/2,0)}
    local OpenRight = {CFrame = CFrame.new(RO)*CFrame.Angles(0,math.pi/2,0)}
    local ClosedRight = {CFrame = CFrame.new(LC)*CFrame.Angles(0,math.pi/2,0)}
    local ClosedLeft = {CFrame = CFrame.new(RC)*CFrame.Angles(0,math.pi/2,0)}
    if workspace.ElevatorRoom.OnFloor.Value ~= FLOOR then
        repeat wait() until workspace.ElevatorRoom.OnFloor.Value == FLOOR 
    elseif workspace.ElevatorRoom.OnFloor.Value == FLOOR and script.Parent.Open.Value == false then
        local openleft = TweenService:Create(script.Parent.Parent.ElevatorFrame.Left, TweenINFO, OpenLeft)
        local openright = TweenService:Create(script.Parent.Parent.ElevatorFrame.Right, TweenINFO, OpenRight)
        script.Parent.Open.Value = true
        openleft:Play()
        openright:Play()
        for i = 5, 1, -1 do
            print(i)
            wait(1)
        end
        local closeleft = TweenService:Create(script.Parent.Parent.ElevatorFrame.Left, TweenINFO, ClosedRight)
        local closeright = TweenService:Create(script.Parent.Parent.ElevatorFrame.Right, TweenINFO, ClosedLeft)
        closeleft:Play()
        closeright:Play()
        script.Parent.Open.Value = false
    end
    print("Ended")
end

return OpenDoorFunction

-- Script --
local OpenDoorModule = require(workspace.ModuleScript)
script.Parent.ClickDetector.MouseClick:Connect(function()
   OpenDoorModule.OpenDoor(
        13.7, 4.4, 35.351,
        13.7, 4.4, 48.451,
        13.7, 4.4, 44.35,
        13.7, 4.4, 39.45,
        1       
        )
end)

If this helped, please accept this answer, If this didn't work then ask questions in the comments

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