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

Door only moves once, not multiple times?

Asked by 4 years ago
Edited 4 years ago

Hi, i'm scripting a moving door when you interact with a proximityprompt but it only works once.

db = true
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
    local character = player.Character
    if character:WaitForChild("CurrentRobbery").Value == "Museum" and db == true then
        db = false
        script.Parent.ProximityPrompt.Enabled = false
        script.Parent.BrickColor = BrickColor.new("Lime green")
        local door = script.Parent.Parent.Parent.Door
        while wait() do
            if door.Position.Y <= 30.94 then
                door.Position = door.Position + Vector3.new(0,0.1,0)
            elseif door.Position.Y == 30.94 then
                break
            else
                wait(10)
                while wait() do
                    if door.Position.Y >= 12.44 then
                        door.Position = door.Position - Vector3.new(0,0.1,0)
                    elseif door.Position.Y == 12.34 then
                        db = true
                        script.Parent.ProximityPrompt.Enabled = true
                        script.Parent.BrickColor = BrickColor.new("Really red")
                        break
                    end
                end
            end
        end
    end
end)

0
In case you are wondering, the positions are just fine. Bankrovers 226 — 4y
0
make db into true when the door finishes opening CrazyCats84 154 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I recommend you actually set the variable "db" to match with it's represented positions. (true, false)

db = true
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
    local character = player.Character
    if character:WaitForChild("CurrentRobbery").Value == "Museum" and db == true then
        db = false
        script.Parent.ProximityPrompt.Enabled = false
        script.Parent.BrickColor = BrickColor.new("Lime green")
        local door = script.Parent.Parent.Parent.Door
        while wait() do
            if door.Position.Y <= 30.94 then
                door.Position = door.Position + Vector3.new(0,0.1,0)
            elseif door.Position.Y == 30.94 then
                break
            else
                wait(10)
                while wait() do
                    if door.Position.Y >= 12.44 then
                        door.Position = door.Position - Vector3.new(0,0.1,0)
            db = false
                    elseif door.Position.Y == 12.34 then
                        db = true
                        script.Parent.ProximityPrompt.Enabled = true
                        script.Parent.BrickColor = BrickColor.new("Really red")
                        break
                    end
                end
            end
        end
    end
end)
0
Thank you! Bankrovers 226 — 4y
Ad

Answer this question