Using require on modules doesnt work

I recently tried modules in my game so i could replace all of the same scripts easily without having to go through every script in the game. And that didn’t work?

The modulescript has no errors because it used to be a server script but i replaced it with a module.

Is there a solution to fix this? If you need the require() script thing here it is:

Server Script:

local ahmodule2 = game:GetService("ServerScriptService"):FindFirstChild("AngleHeadFlashlightGiver")
local ahmodule = require(angleheadmodule2)

ahmodule.activateGiver()

Module:

local module = {}

function module.activateGiver()
	local rep = game:GetService("ReplicatedStorage")

	local tools = rep:WaitForChild("ToolsStuff")
	local straplight = tools:WaitForChild("FlashlightOrangeTorso")
	local sStuff = tools:WaitForChild("StraplightStuff")

	local secitemworkspace = workspace:FindFirstChild("SecondaryItemsWorkspace", true)

	if not secitemworkspace then
		warn("Bro didn't put the secondary item folder to the game, I'm off.")
		return
	end

	script.Parent.Triggered:Connect(function(plr)
		if plr:GetAttribute("OrangeFlashlightEquipped") ~= true then
		--[[local sStuffC = sStuff:Clone()

		sStuffC:MoveTo(Vector3.new(plr.Character:WaitForChild("UpperTorso").CFrame))
		sStuffC.Parent = plr.Character]]

			local straplightCloned = straplight:Clone()

			local stHandle = straplightCloned:WaitForChild("ActualModel"):WaitForChild("Handle")
			local stWeld = stHandle:WaitForChild("PlayerWeldedTo")

			--straplightCloned:MoveTo(Vector3.new(plr.Character:WaitForChild("StraplightStuff"):WaitForChild("StraplightGoTo").CFrame))
			--straplightCloned.ActualModel:MoveTo(Vector3.new(plr.Character:WaitForChild("StraplightStuff"):WaitForChild("StraplightGoTo").CFrame))
			--stra = plr.Character:WaitForChild("StraplightStuff"):WaitForChild("StraplightGoTo").CFrame
			straplightCloned.Parent = secitemworkspace
			straplightCloned.Name = "OrangeFlashlight_".. plr.Name
			straplightCloned:SetAttribute("Owner", plr.Name)
			stWeld.Part1 = plr.Character:WaitForChild("UpperTorso")
			plr:SetAttribute("OrangeFlashlightEquipped", true)
			--straplightCloned.ActualModel.OtherParts:MoveTo(Vector3.new(straplightCloned.ActualModel.PrimaryPart.CFrame))
			--stWeld.Part1 = plr.Character:WaitForChild("UpperTorso")
		end
	end)
end

return module
2 Likes

What’s the issue exactly? What part doesn’t work? Are there any errors?

There are no errors, the issue is:

The modulescript doesnt run at all

If there’s no errors and no warnings, what about:

  • Is there any code causing threads to yield in or out of the module?
  • Where is the module placed and the script that requires it?

You did say it used to be a server script, so I assume there are no LocalScripts involved?

i dont think so

the server script is placed in a proximity prompt inside part thats inside workspace
the module is placed in server script service

You are trying to require something that does not exist in the script.

Consider using this code:

local ahmodule2 = game:GetService("ServerScriptService"):FindFirstChild("AngleHeadFlashlightGiver")
local ahmodule = require(ahmodule2)

ahmodule.activateGiver()

It sometimes doesnt work… Do you have a fix for that ?

What doesn’t work? Elaborate, so I can understand.

the module script doesnt run no matter what

Is the script a LocalScript? Those can’t access ServerScriptService, and consider using :WaitForChild() instead of :FindFirstChild().

Another thing, add a print statement after the local module = {} line.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.