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 3 years ago
Edited 3 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 — 3y
0
make db into true when the door finishes opening CrazyCats84 154 — 3y

1 answer

Log in to vote
0
Answered by 3 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 — 3y
Ad

Answer this question