Is there a way to know when a constraint target has been reached?

Basically my issue is what the title says. I have a PrismaticConstraint in servo mode for an elevator where I want to play a sound when it reaches the top or bottom positions. I have tried using the GetPropertyChangedSignal method to create an event, but it doesn’t fire. Here’s the code for the event handler:

local eventChange = prismaticConstraint:GetPropertyChangedSignal("CurrentPosition"):Connect(function()
	print("Fired")
	if prismaticConstraint.CurrentPosition <= 1 or
		prismaticConstraint.CurrentPosition >= size - 1
	then
		soundStop:Play()
	end
end)

When the elevator platform moves, “Fired” never prints. I read in this post that the reason for this is because the property CurrentPosition is read only.

I have thought of a few solutions to this…

  1. Poll the CurrentPosition property in a timed loop.
  2. Use the Sound.Ended event on the up and down sounds to trigger the playing of the stop sound.
  3. Use a delay timer to trigger the sound based on the travel speed and track height.

#1 will burn CPU cycles on the server which is what I want to avoid. #2 is really a roundabout hack way of doing it and it will be dependent on the length of the mentioned sounds. #3 seems to be the best bet, but I’m not sure about the timing accuracy of the delay global.

Out of those three, which do you think is the best one to use? Or is there another way that I haven’t thought of? To be honest, there really does need to be an event to signal when the target has been reached.

Why is there local eventChange =?

You could try using GetPropertyChangedSignal on the Attachments themselves, checking if they are aligned.

I’d go for option 1, use RunService

@DoorsPro_Bacon Because I was experimenting. I wasn’t sure what I would need to keep track of.

@JoelBrd How would you check if the Attachments themselves are aligned? What property would you use? I thought RunService was only available on the client.

You can query their WorldPosition

RunService.RenderStepped is only available on the client - most other events on RunService are accessible server and client (e.g., Hearbeat)