I want to fire an Event with a ModuleScript - Help

This is what I want to do: there are objects that I can pick up, but to be able to pick them up at any time I was told to use a script module. For this I have made a function in the Script Module which activates my event which causes the object to be picked up. And the script module is linked to a local script, which activates the ModuleScript function when you click on the object to be picked up. But I don’t understand it doesn’t work. Without clicking anywhere I have error messages as if the ModuleScript function had been triggered by itself.

I hope you can help me, thank you. And sorry for my english

Script:

ModuleScript:

local TakeItems = {}

function TakeItems:InT(item)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Event = ReplicatedStorage.TakeEvent

		Event:FireServer(item)	
	end

return TakeItems

LocalScript:

player = game.Players.LocalPlayer

local TakeItems = require(script.ModuleItemsTake)

for i, v in ipairs(workspace:GetDescendants()) do

if v.ClassName == ("ClickDetector") and v.Name == ("ItemDetector") then
	
	local item = v.Parent
	
		v.MouseClick:Connect(TakeItems:InT(item))
		
	end
end

Message error:

image

Specify that the error message occurs without me clicking on the object to take. And besides they disappear as if we had taken them

Ah yes of course I am stupid here it is done thank you!

Ok, so since TakeItems:InT does not return a function you cannot pass its result to RBXScriptSignal::Connect since it does not return anything at all, actually.

Just wrap it in a closure:

v.MouseClick:Connect(function(player)
    TakeItems.InT(item)
end)

By the way you should avoid using : unless you are working with OOP methods.

3 Likes

Okay ! I have to try, then it does not work but now it is when I click on the object that the same error appears. Thank you for taking the time to help me! What is OOP methods ?