Creating Changed events with module scripts?

Greetings,

As many are aware, roblox’s Value objects have a wonderful event that goes buy :Changed

For my purposes, making a lot of these would be counter intuitive, and it works better to use a module script instead.

The question is, how could I achieve similar functionality?

I was thinking of possibly creating a different module to manage it, something that might look like:

local Module = {}

function Module.Changed(ValueToListen)
     local Initial = ValueToListen
    while wait() do
         if ValueToListen ~= Initial then
           Initial = ValueToListen
          return ValueToListen
       end
    end
end

However, I don’t think something like this would work, and if I ended up using it 50 million times I think it would significantly bog down performance.

Any ideas?

Do you not want to use Changed because you only want to listen to one property change as opposed to listen to any property change? If so you can use GetPropertyChangedSignal(), with the parameter being the property it should wait to be changed.

game.Workspace.Part:GetPropertyChangedSignal("Color"):Connect(function()
    print( "The part's color changed!" )
end)

This is an example, it runs whenever part’s color changes.

Besides for the part about it listening for any property to be changed I don’t understand why you wouldn’t want to use it.

I can’t use it, since as I said, I’m storing values in a Module script.

if you’re trying to see when the module table is changed, you can do that by making your original module table a metatable and setting __newindex