When I require a Module it doesn't work

So my problem is is that The Module isn’t loading as the variable and it pauses the whole code I tried debugging with Uno Dos and Tres but only Uno and Dos are loading I’ll also attach a picture of the replicated storage

--///Objects///--
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() or script.Parent
-- local UI = game:GetService("ReplicatedStorage"):WaitForChild("Assets"):WaitForChild("UI"):Clone()
-- UI.Parent = Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
print("UNO")
local Camera = workspace:WaitForChild("Camera")
local Assets = game:GetService("ReplicatedStorage"):WaitForChild("Assets")
local Shared = game:GetService("ReplicatedStorage"):WaitForChild("Shared")
local AnimationFolder = Assets:WaitForChild("Animations")
local Mods = Shared:WaitForChild("Modules")
local Values = Player:WaitForChild("Values")
print("DOS")
local GoalPositions = {}
local Animations = {}
local Remotes = {}
local Movers = require(Mods:WaitForChild("Movers"))
local ActionMod = require(Mods:WaitForChild("ClientAction"))
print("TRES")

image

1 Like

Do these modules return anything? Can you show the code inside please, thanks :slight_smile:

I can comfirm that they both return tables

1 Like

If there’s a hang, it’s usually a sign of a ModuleScript deadly embrace–They’re requiring each-other
(Maybe even another “require-level” down.) So yes, it would help to show the code.

Ok Since you guys asked here

Client Action:

local RunService = game:GetService("RunService")
local Movers = require(script.Parent:WaitForChild("Movers"))
local Action = {}


function Action:FindClosestGoal(Root)
	local distances = {}
	for i, v in pairs(game:GetService("CollectionService"):GetTagged("Goal")) do
		table.insert(distances,(Root.Position-v.Position).magnitude)
		local closest = math.min(unpack(distances))
		for i, v in pairs (game:GetService("CollectionService"):GetTagged("Goal")) do
			local distance2 = (Root.Position-v.Position).magnitude
			if distance2 == closest then
				return v 
			end
		end
	end
end



function Action:GoalMag(Root)
	return (Root.Position - Action:FindClosestGoal(Root).Position).magnitude
end -- End of Goal Mag



function Action:SetupAnimations(Animations,Root)
	if RunService:IsServer() then return end 
	
	Animations.InOutL.KeyframeReached:Connect(function(KeyFrame)-- Start of InoutL KF REached
		if KeyFrame == "Out" then
			Movers:SetVelocity(Root,Root.CFrame.rightVector*11)
		else if KeyFrame == "In" then
			Movers:SetVelocity(Root,-(Root.CFrame.rightVector*13)) 
			end -- End of in
		end-- End of out
	end)-- End of InOutL KF Reached
end-- End of SetupAnimations




return Action

Movers:

local ActionMod = require(script.Parent:WaitForChild("ClientAction"))
	
	
local Movers = {}

function Movers:SetVelocity(Root,Velocity)
	for i, v in pairs(Root:GetChildren()) do
		if v:IsA("BodyVelocity") then
			v:Destroy() 
		end
	end
	local NewVelocity = Instance.new("BodyVelocity",Root)
	NewVelocity.MaxForce = Vector3.new(math.huge,0,math.huge)
	NewVelocity.P = 1350
	NewVelocity.Velocity = Velocity
end


function Movers:SetGyro(Root,Obj)
	for i,v in pairs(Root:GetChildren()) do 
		if v:IsA("BodyGyro") then v:Destroy()
		end
	end 
	print(Root.Parent.Name)
	print(Obj.Parent.Name)
	print(ActionMod:GoalMag(Root))
	local NewGyro = Instance.new("BodyGyro",Root)
	NewGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	NewGyro.D = 6000
	NewGyro.P = 2000000
	NewGyro.CFrame = CFrame.new(Root.Position,Vector3.new(Obj.Position.X,Root.Position.Y,Obj.Position.Z))
end

function Movers:StopMovers(Mover,Root)
	if Mover == "Velocity" then
		for i, v in pairs(Root:GetChildren()) do
			if v:IsA("BodyVelocity") then
				v:Destroy() 
			end
		end
	else if Mover == "Gyro" then
			for i,v in pairs(Root:GetChildren()) do 
				if v:IsA("BodyGyro") then v:Destroy()
				end
			end 
		else if Mover == "All" then
				for i, v in pairs(Root:GetChildren()) do
					if v:IsA("BodyVelocity") then
						v:Destroy() 
					end
				end
				for i,v in pairs(Root:GetChildren()) do 
					if v:IsA("BodyGyro") then v:Destroy()
					end
				end 
			end
		end
	end

end


return Movers


I see the problem here. Movers modulescript is requiring Client Action modulescript in it’s code then Client Action modulescript requires Movers modulescript in it’s code which requires Client Action modulescript and this forms a require loop that goes on forever and since require() yields the code until it gets a result, main code halts forever because of this.

So How would I fix this though I need both of them to be required

Cyclic dependencies are bad coding practice in general, you should try to avoid them.

There are a few posts on this site already answering this question. Maybe have a look at this post.

Yeah don’t do this. Bad practice. Ever since I ran into this problem, I’ve changed my habits and have had much better luck.

1 Like