I have a door that is supposed to open if you are on the right team. It goes up and down alright the first time, but the second time, it goes up to your head height then rapidly bounces up and down 1 stud until you exit the door. When you exit the door, it closes like it should, but it glitches out again when you open it. If you want to see it in action, you can look at it here by touching the dark wall. Also note that the door is anchored. Here is the code:
local Door = script.Parent
local Color = "New Yeller"
local DB = false
function Open()
print("Opening")
while Door.Position.Y < 98.5 do
Door.Position = Door.Position + Vector3.new(0, 0.75, 0)
wait(0.05)
end
end
function Close()
print("Closing")
while Door.Position.Y > 83.5 do
Door.Position = Door.Position - Vector3.new(0, 0.75, 0)
wait(0.05)
end
end
function onTouch(part)
if game.Players:GetPlayerFromCharacter(part.Parent) and DB == false then
local Player = game.Players:GetPlayerFromCharacter(part.Parent)
if Player.TeamColor == BrickColor.new(Color) then
DB = true
Open()
wait(2)
Close()
wait(2)
DB = false
end
end
end
Door.Touched:connect(onTouch)
Any Suggestions?

1 comment
Thanks! I completely forgot about for loops :P