Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Door only moves once, not multiple times?

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)

2 comments

0

In case you are wondering, the positions are just fine.

0

make db into true when the door finishes opening

1 answer

✓ Accepted answer

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)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.