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…
- Poll the
CurrentPosition
property in a timed loop. - Use the
Sound.Ended
event on the up and down sounds to trigger the playing of the stop sound. - 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.