Custom :GetPropertyChangedSignal Questions

I want to make a form of Instance:GetPropertyChangedSignal.

My plan of achieving this would be:

local StoredValue = 3424243
game["Run Service"].Heartbeat:Connect(function()
    if Value ~= StoredValue then
        StoredValue = Value
        PropertyChangedSignal:Fire()
    end
end

Would this be an acceptable way of achieving this?
Would this cause any major performance issues?
Are there any better ways of achieving this?

Edit:
I am making a custom object, not an instance, hence why I am forced to create a custom GetPropertyChangedSignal

Um I am not totally sure but would this script not work as you have not added in what Property you want it to check that changed?

You’re trying to make your own version of it? If so, then yes, the best way that comes to my mind is check if the value has changed every <time period>, and if it has changed, do something, and set the value. As for performance, I’m not sure, you’d have to test out the differences between each different method.

If you’re trying to use GetPropertyChangedSignal, however,

Instance:GetPropertyChangedSignal("Property"):Connect(function()
    local Property = Instance.Property
    -- Property would be the property, Instance.<Property> replaced 
    -- with the argument you used in GetPropertyChangedSignal
end)

I don’t understand why you can’t just use GetPropertyChangedSignal? Your new “form” is far more inefficient at checking value changes.

If what I were using was an instance, I would use :GetPropertyChangedSignal, but what I am doing is creating custom objects, which do not have that function attached unless I were to make a custom version, which I am doing here.

You would do something like this:

local changedEvent = Instance.new("BindableEvent")
local StoredValue = 3424243

changedEvent.Event:Connect(function()
    print("changed") -- the event was fired so it changed
end)

game:GetService("RunService").Heartbeat:Connect(function()
    if Value ~= StoredValue then
        StoredValue = Value
        changedEvent:Fire() -- fire the event
    end
end
1 Like

Of course. Make a setter function that is used to set a new value to your variable and in that function fire your custom PropertyChangedSignal event.