I just wanted to know how to loop a elevator with prismatic constraint using TargetPosition.
The elevator has simple tasks: point a to point b then repeat.
I tried some ways like “while true do” or “repeat … until …” and even debounce.
But they aren’t seems to work…
I’m asking because i didnt seen nobody doing questions about. I never looped a constraint in general… ;-;
If it’s only doing a wait, go up, then wait, go down just do something like this, but change your waits and TargetPositions to whatever you want.
while true do
PrismaticConstraint.TargetPosition = 0
wait(15)
PrismaticConstriant.TargetPosition = 100
wait(15)
end
If the Elevator isn’t working at all then do you have any Parts Anchored, or welded to Anchored Parts? The AcutatorType needs to be set to Servo, and your ServoMaxForce should be pretty high.
Also have a look at the Attachment alignment by clicking the Constraints Visible tool up in the Model tab in Studio, then the View on Top tool. When you click on your PrismaticConstraint and Attachments they should all be aligned with the yellow arrow pointing in the direction of travel, and the yellow and orange arrows need to be aligned the same way as well.
The welds works fine and parts are all unanchored in the model. I’m just going to say the wait() system look kinda raw for me.
I wonder if is there a precise way.
meanwhile, I’m using your suggestion as a temporary solution.
What exactly are you trying to achieve? There aren’t many more efficient ways to write what @Scottifly said which seems to be working for you?
Well i mean the elevator do the action to go down and wait until it reach the point b then the loop restart.
Making a timing based on the TargetPosition i mean.
Prismatic Constriants have a CurrentPosition Property that can be read from.
You could check that until the CurrentPosition = TargetPosition
, then do your wait(time)
then.
I don’ t understand if it still in a while true do loop or in repeat … until …
And where i should put the wait?
Like a the end of the line or under the line of code.
Could you show me an example?
Something like this:
while true do
while PrismaticConstraint.CurrentPosition >= 0 or PrismaticConstraint.CurrentPosition <= 100 then -- in transit, but don't make it exactly zero or 100
wait(.5) -- check every half second to see if it's still in between top and bottom
else
wait(15) -- when it's at top or bottom then wait 15 (or whatever you want)
end
if PrismaticConstraint.TargetPosition == 0 then -- switches the TargePosition back and forth
PrismaticConstraint.TargetPosition = 100
else
PrismaticConstriant.TargetPosition = 0
end
end
[/quote]
Ok i think it worked the elevator did the check then it started to go with the right timing.
I tested with the print codes and seen it count two times the 0.5 wait first.
I replaced while with if because roblox studio keep warning me and switched the first two numbers in the check condition.
Haha, yeah. Sorry about that, I just had while in my brain when I did the second line.