Function not connecting with right end


so i’m working on something elevator like and i have a script for it (i am working with BodyPosition) and things just don’t connect well

this is my script :

local platform = script.Parent

local fini = script.Parent.Parent.fini
local start = script.Parent.Parent.start

local startPos = start.Position
local endPos = fini.Position

local BP = script.Parent.BodyPosition

while true do

	BP.Position = endPos
	until platform.Position = endPos

	BP.Position = startPos
	until platform.Position = startPos



the while true do connects with the second until and not with the end. I hope I made this clear (my english is not that good). WHAT DO I DO?

until condition

Isn’t valid syntax - the interpretter thinks your until is for closing the while, as wait doesn’t create a new scope. If you want to wait for a property to reach a given value, you need to check it whenever it changes.

--Define a function that handles what to do whenever the position is changed.
local onPositionChanged = function()
    if platform.Position == endPos then
        BP.Position = endPos
    elseif platform.Position == startPos then
        BP.Position  = startPos
--Run the function whenever the position of the platform changes.

As an aside, you can create a “wait until” if you have an event which fires whenever your condition is met, like this:


Though for your case there isn’t an event you can use for this, so you’ll need to use the method above.

30 chars 30 chars