I’m trying to make a script where it’ll execute a function when there are changes on the SpringConstraint, and to my knowledge, the only property of the SpringConstraint that isn’t a constant would be the CurrentLength. But when I tried to apply it with the GetPropertyChangedSignal which in my understanding is supposed to detect property changes, it doesn’t look like its detecting anything while testing…
Here’s the entire script for reference:
local part = script.Parent
local springConstraint = part:FindFirstChildOfClass("SpringConstraint")
local creakingVolume = 0.5
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9116604303"
sound.Volume = creakingVolume
sound.Parent = part
local function playCreak()
if not sound.IsPlaying then
sound:Play()
end
end
local function checkCreaking()
print("Changed")
playCreak()
end
springConstraint:GetPropertyChangedSignal("CurrentLength"):Connect(checkCreaking)
I know physics-related changes don’t typically fire GetPropertyChangedSignal on parts for performance reasons, so I would guess this is the case for constraints as well. You might have to repeatedly query the spring.CurrentLength to monitor for changes
When I tested it, it says that the CurrentLength cannot change and it is a read only property. Maybe trying detecting a change in the magnitude between the two attachments with a while loop?
Isnt :GetPropertyChangedSignal a method? It might just be because for some reason you are connecting it to a function when you can’t because it’s not an event, use the .Changed event instead which detects changes to properties, read only values like CurrentLength will still have their properties change to answer that other guy, so you can detect the changes.
.Changed is a property of type RBXScriptSignal that detects every change, and you can therefore just do .Changed:Connect(..., but having one property for each property to detect .Changed for that one specifically would be very inefficient.
So isntead this method :GetPropertyChangedSignal() returns a RBXScriptSignal that only specifically detects that one property. Just how :IsA() is a method that returns a bool :GetPropertyChangedSignal() returns a signal.
:GetPropertyChangedSignal() is a method that returns a RBXScriptSignal .Changed is a property that returns is a RBXScriptSignal
only difference is one detects all property changes, and the other only detects one.
I know the differences between them, but my question is why is OP using :Connect on a method? I haven’t tested it on studio, but I’m fairly certain you can’t use :Connect on methods. Nevermind turns out you can. No need for a reply. My life is a lie. And I didn’t mean all methods in general I just meant that in this one you somehow can. I get it returns a RBXScriptsignal so you can then use :Connect to make it a RBXScriptConnection.
It is pretty confusing, because I think :GetPropertyChangedSignal() and :GetAttributeChangedSignal() are the two only methods that return a signal. But it’s essentially the same as a property method