How to Fix "Attempt to connect failed: Passed value is not a function"?

Hello!

I’m trying to get a Module Script but for some reason i’m getting an red underline, even if i typed everything correctly, and i made sure the location of the module is correct (it even autocompleted itself)

Here’s the script:

local BarrierFolder = script.Parent

for _, Barrier in pairs(BarrierFolder:GetDescendants()) do
	if Barrier:IsA("BasePart") then
		
		Barrier.Touched:Connect(function(Hit)
			
			if Hit.Parent:FindFirstChild('Humanoid') then
				
				local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
				local Character = Player.Character or Player.CharacterAdded:Wait()
				
				local PlayerGui = Player.PlayerGui
				local DialogueModule = require(PlayerGui.Dialogue:WaitForChild('DialogueModule'))
				
				DialogueModule.Dialog('That area is restricted')
			end
		end)
	end
end

(the underline is below “require(PlayerGui.Dialogue:WaitForChild(‘DialogueModule’))”)

Thanks for the help :smiley:

It’s also happening for other module scripts in the game

Your code seems fine to me, it’s possible that there might be an issue inside of the Module itself. Where is error happening though? What type of the script is it? Where exactly is it located?

1 Like

i don’t see anything wrong with the module either…

local dialogMod = {}

local Dialogue = script.Parent
local Text = Dialogue.Text

function DialogueModule.Dialog(Tx, WaitTime)
	local WaitTime = 5 or WaitTime
	
	task.spawn(function()
		Text.Text = Tx
		task.wait(WaitTime)
		Text.Text = ""
	end)
end

return dialogMod

Change DialogueModule in the function to dialogMod.

If you are trying to add a function to the module the names must be the same!

1 Like

still doesn’t work for some reason

for some reason it’s underlined but it still works. thanks for the help though!

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