Can't require() a module script

Hello.


So here all i’m trying to do is require() a module script. Like I did here:


But the print("Moduleeeee") doesn’t work.


Here is a picture of my Explorer. The E script inside the remote is the one that requires the module script. The module script is the thing called DamageModule.


Can anyone help me?

Could there be anything in the DamageModule that is halting? Can you show us what’s in DamageModule? Your WaitForChild shouldn’t be the issue since You located the module correctly

1 Like

Here is the DamageModule :

--< SERVICES >--

local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local plrs = game:GetService("Players")
local debris = game:GetService("Debris")

------------------------------------------------------------------------------------------------------------

--< VARIABLES >--

local damageIndicatorInfos = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)

local abbreviations = {"", "K", "M", "B", "T" , "Qd", "Qn", "Sx", "Sp", "Oc", "No", "Dc", "Un", "Duo", "Tre", "Qua", "Qui", "Sed", "Sep", "Oct", "Nov", "V"}
local damageModule = {}

------------------------------------------------------------------------------------------------------------

--< FUNCTIONS >--

local function Format(value, idp)
	local ex = math.floor(math.log(math.max(1, math.abs(value)),1000))
	local abbrevs = abbreviations[1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ idp) / (1000 ^ ex))) / (10 ^ idp)
	return ("%."..idp.."f%s"):format(normal, abbrevs)
end

------------------------------------------------------------------------------------------------------------

--< MODULE FUNCTION >--

damageModule.Damage = function(hit, tool, damage, bloodDuration)
	
	local alreadyHit = {}
	local damageIndicator = rs:WaitForChild("DamageBillboard"):Clone()
	local hitSound = script:WaitForChild("HitSound"):Clone()
	local enemyCharacter = hit.Parent
	local enemyHumanoid = enemyCharacter:FindFirstChildOfClass("Humanoid")
	local isMob = enemyCharacter:FindFirstChild("IsMob")
	local isBlocking = enemyCharacter:FindFirstChild("IsBlocking")
	local damageDealer = plrs:GetPlayerFromCharacter(tool.Parent)
	
	local function TagHumanoid()
		local Creator_Tag = Instance.new("ObjectValue")
		Creator_Tag.Name = "creator"
		Creator_Tag.Value = damageDealer
		game.Debris:AddItem(Creator_Tag, 2)
		Creator_Tag.Parent = enemyHumanoid
	end
	
	local function SoulEffect()
		local soulEffectBeam = rs:WaitForChild("SoulEffect"):Clone()
		soulEffectBeam.Parent = workspace
		local attachment0 = Instance.new("Attachment", enemyCharacter:WaitForChild("Head"))
		local attachment1 = Instance.new("Attachment", tool:WaitForChild("Handle"):FindFirstChild("Sword"))
		soulEffectBeam.Attachment0 = attachment0
		soulEffectBeam.Attachment1 = attachment1
		wait(2.5)
		soulEffectBeam:Destroy()
	end
	
	if enemyCharacter.Name == damageDealer.Character.Name then return end
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		
		
			if isMob then
				
				if isBlocking.Value == false then
					if table.find(alreadyHit, hit.Parent) then return
					else
							local blood = rs:WaitForChild("Blood"):WaitForChild("Attachment"):Clone()
							blood.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
							hitSound.Parent = hit.Parent
							damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
							damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage, 0))
							ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
							debris:AddItem(blood, bloodDuration)
							debris:AddItem(hitSound, 3)
							debris:AddItem(damageIndicator, 3)
							hitSound:Play()
							TagHumanoid()
							enemyHumanoid.Died:Connect(SoulEffect)
							hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
							table.insert(alreadyHit, hit.Parent)
						end
					end
					
				if isBlocking.Value == true then
					if table.find(alreadyHit, hit.Parent) then return
					else
							hitSound.Parent = hit.Parent
							damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
							damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage / 2, 0))
							damageIndicator:WaitForChild("TextLabel").TextColor3 = Color3.fromRGB(83, 201, 255)
							ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
							debris:AddItem(hitSound, 3)
							debris:AddItem(damageIndicator, 3)
							hitSound:Play()
							TagHumanoid()
							enemyHumanoid.Died:Connect(SoulEffect)
							hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage / 2)
							table.insert(alreadyHit, hit.Parent)
						end
					end
				
			else
				
				if isBlocking.Value == false then
					if table.find(alreadyHit, hit.Parent) then return
					else
						local blood = rs:WaitForChild("Blood"):WaitForChild("Attachment"):Clone()
						blood.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
						hitSound.Parent = hit.Parent
						damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
						damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage, 0))
						ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
						debris:AddItem(blood, bloodDuration)
						debris:AddItem(hitSound, 3)
						debris:AddItem(damageIndicator, 3)
						hitSound:Play()
						TagHumanoid()
						enemyHumanoid.Died:Connect(SoulEffect)
						hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
						table.insert(alreadyHit, hit.Parent)
					end
				end

				if isBlocking.Value == true then
					if table.find(alreadyHit, hit.Parent) then return
					else
						hitSound.Parent = hit.Parent
						damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
						damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage / 2, 0))
						damageIndicator:WaitForChild("TextLabel").TextColor3 = Color3.fromRGB(83, 201, 255)
						ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
						debris:AddItem(hitSound, 3)
						debris:AddItem(damageIndicator, 3)
						hitSound:Play()
						TagHumanoid()
						enemyHumanoid.Died:Connect(SoulEffect)
						hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage / 2)
						table.insert(alreadyHit, hit.Parent)
					end
				end
			
			end	
	end
end

------------------------------------------------------------------------------------------------------------

--< RETURNING MODULE >--

return damageModule

And if you’re wondering what the hit paramenter is, basically (from the server script) i’m calling the module script when they touch a part.

Did you check in the explorer if the Damage Module still exist prior to you playtesting the game in studio?

1 Like

ServerScripts dont need to use WaitForChild in most cases. Try Require it without the WaitForChild or switching to FindFirstChild.

1 Like

Nope. Unfortunately, I tried both but it still doesn’t print “Moduleeeee”

Is the tool located in workspace when the module is required? What may be happening is that it is printing but since in Studio you are on the client, You aren’t seeing the server output

1 Like

No, it’s in the StarterPack. How can I make it so it prints in the server?

You can try putting it in workspace as a test or when you play the game switch the output to server

1 Like

It works in the Workspace. But I would like it to work also when I have the tool in the Backpack tho…

The module will be required even if it is in starterpack, You just won’t see the print on the client.

1 Like

Oh okay, so the I won’t see the print in the Output but my code will still work?

Yep! Since you are using a serverscript to print the code, This will run on the server. When you play the game you are automatically on the client and the client does not have access to the server.

1 Like

Does it send an error starting with infinite yield on? If no, this means the code works perfectly fine.

2 Likes

If the problem is resolved, Make sure to mark it as solved so other people who have this problem can find the fix easily.

2 Likes