I created a tardis that is suppose to teleport to 2 different times of a place. My script however keeps looping itself for like 5 times and then it resets to the default values.

local button = workspace.place
local teleport = workspace.TP.Head
local back = workspace.back.Head
function onClick()
	teleport.Enabled.Value = '1'
end
button.ClickDetector.MouseClick:connect(onClick)

function onTouch(part)
    wait(1)	
	teleport.Enabled.Value = '0'
	wait(20)
	back.Enabled.Value = '1'
	wait(1)
	back.Enabled.Value = '0'
	
end
teleport.Touched:connect(onTouch)

The teleport script is below which I did not make. though If you have any simplifications for it that would be nice.

--Made By Adrian928
------------------------------------
modelname="tele2" 
------------------------------------
--          ^ Name that.

function onTouched(part)
	if part.Parent ~= nil then
	local h = part.Parent:findFirstChild("Humanoid")
		if h~=nil then
			local teleportfrom=script.Parent.Enabled.Value
			if teleportfrom~=0 then
				if h==humanoid then
				return
				end
				local teleportto=script.Parent.Parent:findFirstChild(modelname)
				if teleportto~=nil then
					local torso = h.Parent.Torso
					local location = {teleportto.Position}
					local i = 1

					local x = location[i].x
					local y = location[i].y
					local z = location[i].z
				
					x = x + math.random(-1, 1)
					z = z + math.random(-1, 1)
					y = y + math.random(2, 3)

					local cf = torso.CFrame
					local lx = 0
					local ly = y
					local lz = 0
					
					script.Parent.Enabled.Value=0
					teleportto.Enabled.Value=0
					torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
					wait(1)
					script.Parent.Enabled.Value=1
					teleportto.Enabled.Value=1
				else
					print("Could not find teleporter!")
				end
			end
		end
	end
end

script.Parent.Touched:connect(onTouched)

My script outputs show 0 errors and I cannot figure out what the issue is with this.