I want a function to play when the PrismaticContraint reaches a certain position I tried to use a while loop before but even when the correct number is displayed it still loops without doing what I want
you could try like
PrismaticConstraint:GetPropertyChangedSignal('CurrentPosition'):Connect(function() if PrismaticConstraint.CurrentPosition >= desiredposition then loop:Disconnect() end end)
this script assumes that the other loop is hooked to like heartbeat or renderstepped and not a while wait
The constraint is an elevator and I can’t rely all on wait to do things
If you can show us your other script we can better help you.
@hockeylover29’s solution will work if you’re using any form of loop, just replace loop:disconnect() with a flag/boolean e.g. active = false and where your loop is functioning, break it at ‘not active’.
Similarly, this could also be used to set the constraint’s speed to 0 when the position is reached.
function SendElevatorUp()
print("d")
Floor0.Door00Floor00.Door01Power.PrismaticConstraint.TargetPosition = 2.7
Floor0.Door01Floor00.Door01Power.PrismaticConstraint.TargetPosition = 2.7
Floor1.Door00Floor01.Door01Power.PrismaticConstraint.TargetPosition = 2.7
Floor1.Door01Floor01.Door01Power.PrismaticConstraint.TargetPosition = 2.7
wait(1)
ElevatorDoors.RightSide.PrismaticConstraint.TargetPosition = 0
ElevatorDoors.LeftSide.PrismaticConstraint.TargetPosition = 0
script.Parent.MainPower.PrismaticConstraint.TargetPosition = 61
wait(1)
if script.Parent.MainPower.PrismaticConstraint.CurrentPosition ~= 61 then
repeat wait() until script.Parent.MainPower.PrismaticConstraint.CurrentPosition == 61
end
if script.Parent.MainPower.PrismaticConstraint.CurrentPosition == 61 then
wait(1)
Floor1.Door00Floor01.Door01Power.PrismaticConstraint.TargetPosition = 0
Floor1.Door01Floor01.Door01Power.PrismaticConstraint.TargetPosition = 0
wait(1)
ElevatorDoors.RightSide.PrismaticConstraint.TargetPosition = 2.7
ElevatorDoors.LeftSide.PrismaticConstraint.TargetPosition = 2.7
end
Floor1.Door00Floor01.Door01Power.PrismaticConstraint.TargetPosition = 2.7
Floor1.Door01Floor01.Door01Power.PrismaticConstraint.TargetPosition = 2.7
wait(1)
end
SendElevatorUp()