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
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)
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.
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