Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to tell a script to wait if something is complete?

Asked by 7 years ago
Edited 7 years ago

I'm making a door which opens using Vector3 but how do I tell it to not continue moving once it has reached a set position?

LDoor = game.Workspace.OpeningD.LDoor
RDoor = game.Workspace.OpeningD.RDoor
IsRunning = true
function OpenDoor()
    if IsRunning == true then
        IsRunning = false
    while true do
        LDoor.CFrame = LDoor.CFrame - Vector3.new(0,0,0.1)
        RDoor.CFrame = RDoor.CFrame + Vector3.new(0,0,0.1)
        wait(0.01)
            OpenDoor = false
            IsRunning = false
        end
    end
end

script.Parent.ClickDetector.mouseClick:connect(OpenDoor)

2 answers

Log in to vote
2
Answered by 7 years ago

make an if statement

LDoor = game.Workspace.OpeningD.LDoor
RDoor = game.Workspace.OpeningD.RDoor
IsRunning = true
function OpenDoor()
    if IsRunning == true then
        IsRunning = false
    while true do
    if LDOOR.CFrame ~= CFrame.new(0,0,100) then
        LDoor.CFrame = LDoor.CFrame - Vector3.new(0,0,0.1)
        RDoor.CFrame = RDoor.CFrame + Vector3.new(0,0,0.1)
        wait(0.01)
            OpenDoor = false
            IsRunning = false
        end
end
    end
end

script.Parent.ClickDetector.mouseClick:connect(OpenDoor)
Ad
Log in to vote
1
Answered by
Etheroit 178
7 years ago
Edited 7 years ago

This is fixed script Upper one will not work

LDoor = game.Workspace.OpeningD.LDoor
RDoor = game.Workspace.OpeningD.RDoor

-- StartCFrame = RDoor.CFrame -- Used to the closing function (Delete comment if u want to use this)
EndCFrame = RDoor.CFrame * CFrame.new(0, 0, 5) -- It will end when it will move 5 studs You can change this

IsRunning = false
function OpenDoor()
    if IsRunning == false then
    IsRunning = true
    while isRunning do
        LDoor.CFrame = LDoor.CFrame * CFrame.new(0, 0, 0.1):inverse() -- You cant use - + You can only use * and / so there must be invertion
        RDoor.CFrame = RDoor.CFrame * CFrame.new(0, 0, 0.1)
        wait(0.01)
         if RDoor.CFrame == EndCFrame then -- When right door reach choosen location it will stop
            IsRunning = false
        end
    end
    --[[ -- If you want there is the closing function (Delete comment if you want to use this)
    isRunning = true
    while isRunning
        LDoor.CFrame = LDoor.CFrame * CFrame.new(0, 0, 0.1)
        RDoor.CFrame = RDoor.CFrame * CFrame.new(0, 0, 0.1):inverse()
        wait(0.01)
         if RDoor.CFrame == StartCFrame then
            IsRunning = false
        end
    end
    ]]
end

script.Parent.ClickDetector.mouseClick:connect(OpenDoor)

Answer this question