Module Error. attempt to index function with 'Changed'

Module =>

local Onx = setmetatable({}, {__index = function()
	  return error(-1)
end,})

function Onx:getState(ASSET : any, THREAD_OR_FUNCTION : "ThreadOrFunction")
	if (typeof(THREAD_OR_FUNCTION) ~= 'function' or ASSET ~= nil) then
		
	--<================================================================>	
		
		local Respond, Caught = pcall(coroutine.wrap(function()
			return ASSET.Changed:Connect(THREAD_OR_FUNCTION)
		end)) if not (Respond) then return error("Couldn't Update") end
		
	--<================================================================>	
		
	else return error(string.format("Type Passed => %s", type(THREAD_OR_FUNCTION) )) end
end

return Onx

Server =>

local OpenOnx = require(game:GetService("ReplicatedStorage").OpenOnx)
local Part = game:GetService("Workspace").Part

OpenOnx.getState(Part, function()
	print("Updated!")
end)

Part.Changed:Connect()

task.wait(5)
Part.BrickColor = BrickColor.Random()

Do you have a line number? A stack trace?

Debugging on your own is really important. You’re the one who understands your script the best. If you printed out ASSET which is presumably related to the issue, you’d probably see that it was a function instead of whatever you were expecting. From there, you can try to figure out why it’s not right: move some parameters around, see if you can figure out why a whole parameter is just disappearing. If, at that point, you still needed help, you would already have had plenty of information for us to work with, instead of just some descriptionless scripts and 25% of an error message.

Fortunately, we’re pretty awesome here, and I think I see the problem anyways. It looks like you’re calling an OOP method with the traditional dot operator instead of a colon.

1 Like

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